HHH-10531 JaxbHbmTuplizerType marshalling does not conform hibernate-mapping-4.0.xsd
HHH-10532 Cannot marshall JaxbHbmBasicAttributeType to xml if the "generated" attribute is not specified
This commit is contained in:
parent
fde8b608fc
commit
26df5d9e11
|
@ -17,6 +17,6 @@ public class EntityModeConverter {
|
|||
}
|
||||
|
||||
public static String toXml(EntityMode entityMode) {
|
||||
return entityMode.name();
|
||||
return ( null == entityMode ) ? null : entityMode.getExternalName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@ public class GenerationTimingConverter {
|
|||
}
|
||||
|
||||
public static String toXml(GenerationTiming generationTiming) {
|
||||
return generationTiming.name().toLowerCase( Locale.ENGLISH );
|
||||
return ( null == generationTiming ) ?
|
||||
null :
|
||||
generationTiming.name().toLowerCase( Locale.ENGLISH );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.boot.jaxb.hbm.internal;
|
||||
|
||||
import org.hibernate.EntityMode;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmRootEntityType;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSimpleIdType;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmTuplizerType;
|
||||
import org.hibernate.tuple.entity.DynamicMapEntityTuplizer;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Jean-François Boeuf
|
||||
*/
|
||||
public class EntityModeConverterTest extends BaseUnitTestCase {
|
||||
|
||||
@Test
|
||||
public void testMashallNullEntityMode() throws Exception {
|
||||
XmlBindingChecker.checkValidGeneration( generateXml( false ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMashallNotNullEntityMode() throws Exception {
|
||||
XmlBindingChecker.checkValidGeneration( generateXml( true ) );
|
||||
}
|
||||
|
||||
private JaxbHbmHibernateMapping generateXml(boolean includeEntityMode)
|
||||
throws Exception {
|
||||
JaxbHbmHibernateMapping hm = new JaxbHbmHibernateMapping();
|
||||
JaxbHbmRootEntityType clazz = new JaxbHbmRootEntityType();
|
||||
JaxbHbmTuplizerType tuplizer = new JaxbHbmTuplizerType();
|
||||
tuplizer.setClazz( DynamicMapEntityTuplizer.class.getCanonicalName() );
|
||||
if ( includeEntityMode ) {
|
||||
tuplizer.setEntityMode( EntityMode.MAP );
|
||||
}
|
||||
clazz.getTuplizer().add( tuplizer );
|
||||
JaxbHbmSimpleIdType id = new JaxbHbmSimpleIdType();
|
||||
clazz.setId( id );
|
||||
hm.getClazz().add( clazz );
|
||||
return hm;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.boot.jaxb.hbm.internal;
|
||||
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmBasicAttributeType;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmRootEntityType;
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmSimpleIdType;
|
||||
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Jean-François Boeuf
|
||||
*/
|
||||
public class GenerationTimingConverterTest extends BaseUnitTestCase {
|
||||
|
||||
@Test
|
||||
public void testMashallAttributeWithNullGenerationTiming()
|
||||
throws Exception {
|
||||
JaxbHbmHibernateMapping hm = new JaxbHbmHibernateMapping();
|
||||
JaxbHbmRootEntityType clazz = new JaxbHbmRootEntityType();
|
||||
JaxbHbmSimpleIdType id = new JaxbHbmSimpleIdType();
|
||||
JaxbHbmBasicAttributeType att = new JaxbHbmBasicAttributeType();
|
||||
att.setName( "attributeName" );
|
||||
clazz.getAttributes().add( att );
|
||||
clazz.setId( id );
|
||||
hm.getClazz().add( clazz );
|
||||
|
||||
XmlBindingChecker.checkValidGeneration( hm );
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
|
||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||
*/
|
||||
package org.hibernate.test.boot.jaxb.hbm.internal;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.Marshaller;
|
||||
|
||||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.boot.spi.XmlMappingBinderAccess;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* @author Jean-François Boeuf
|
||||
*/
|
||||
public class XmlBindingChecker {
|
||||
|
||||
public static void checkValidGeneration(JaxbHbmHibernateMapping hbmMapping)
|
||||
throws Exception {
|
||||
JAXBContext jaxbContext = JAXBContext
|
||||
.newInstance( JaxbHbmHibernateMapping.class );
|
||||
|
||||
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
|
||||
jaxbMarshaller.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, true );
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
jaxbMarshaller.marshal( hbmMapping, bos );
|
||||
ByteArrayInputStream is = new ByteArrayInputStream( bos.toByteArray() );
|
||||
ServiceRegistry sr = new StandardServiceRegistryBuilder().build();
|
||||
new XmlMappingBinderAccess( sr ).bind( is );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue