HHH-14563 Remove legacy tests for DOM4J-based XML mapping
This commit is contained in:
parent
4f7bb75ec7
commit
194e53a0fb
|
@ -1,78 +0,0 @@
|
|||
/*
|
||||
* 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.internal.util.xml;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
import org.dom4j.DocumentFactory;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.xml.sax.EntityResolver;
|
||||
|
||||
/**
|
||||
* Small helper class that lazily loads DOM and SAX reader and keep them for fast use afterwards.
|
||||
*
|
||||
* This was part of Hibernate ORM core, but moved into the testsuite helpers to not expose
|
||||
* access to the dom4j types. It's also used by Hibernate Envers, so we will need two copies
|
||||
* until Envers is able to remove its reliance on dom4j.
|
||||
* The rest of Hibernate uses StAX now for XML processing. See {@link org.hibernate.boot.jaxb.internal.stax}
|
||||
*/
|
||||
public final class XMLHelper {
|
||||
private final DocumentFactory documentFactory;
|
||||
|
||||
public XMLHelper() {
|
||||
PrivilegedAction<DocumentFactory> action = new PrivilegedAction<DocumentFactory>() {
|
||||
public DocumentFactory run() {
|
||||
final ClassLoader originalTccl = Thread.currentThread().getContextClassLoader();
|
||||
try {
|
||||
// We need to make sure we get DocumentFactory
|
||||
// loaded from the same ClassLoader that loads
|
||||
// Hibernate classes, to make sure we get the
|
||||
// proper version of DocumentFactory, This class
|
||||
// is "internal", and should only be used for XML
|
||||
// files generated by Envers.
|
||||
|
||||
// Using the (Hibernate) ClassLoader that loads
|
||||
// this Class will avoid collisions in the case
|
||||
// that DocumentFactory can be loaded from,
|
||||
// for example, the application ClassLoader.
|
||||
Thread.currentThread().setContextClassLoader( this.getClass().getClassLoader() );
|
||||
return DocumentFactory.getInstance();
|
||||
}
|
||||
finally {
|
||||
Thread.currentThread().setContextClassLoader( originalTccl );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.documentFactory = System.getSecurityManager() != null
|
||||
? AccessController.doPrivileged( action )
|
||||
: action.run();
|
||||
}
|
||||
|
||||
public DocumentFactory getDocumentFactory() {
|
||||
return documentFactory;
|
||||
}
|
||||
|
||||
public SAXReader createSAXReader(ErrorLogger errorLogger, EntityResolver entityResolver) {
|
||||
SAXReader saxReader = new SAXReader();
|
||||
try {
|
||||
saxReader.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", false );
|
||||
saxReader.setFeature( "http://xml.org/sax/features/external-general-entities", false );
|
||||
saxReader.setFeature( "http://xml.org/sax/features/external-parameter-entities", false );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException( e );
|
||||
}
|
||||
saxReader.setMergeAdjacentText( true );
|
||||
saxReader.setValidation( true );
|
||||
saxReader.setErrorHandler( errorLogger );
|
||||
saxReader.setEntityResolver( entityResolver );
|
||||
|
||||
return saxReader;
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.reflection;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests the legacy {@link JPAOverriddenAnnotationReader},
|
||||
* which will be replaced with {@link org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenAnnotationReader}.
|
||||
* {@link JPAOverriddenAnnotationReader} is still the default implementation,
|
||||
* but we want to switch to {@link org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenAnnotationReader}
|
||||
* as soon as it will be practical.
|
||||
*
|
||||
* @see JPAXMLOverriddenAnnotationReaderTest
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
@TestForIssue( jiraKey = "HHH-11924")
|
||||
public class LegacyElementCollectionConverterTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
Company.class,
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getXmlFiles() {
|
||||
return new String[] { "org/hibernate/test/annotations/reflection/element-collection-converter-orm.xml" };
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testConverterIsAppliedToElementCollection() {
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
Company company = new Company();
|
||||
company.setId( 1L );
|
||||
|
||||
Organization org1 = new Organization();
|
||||
org1.setOrganizationId( "ACME" );
|
||||
|
||||
company.getOrganizations().add( org1 );
|
||||
|
||||
session.persist( company );
|
||||
} );
|
||||
|
||||
doInHibernate( this::sessionFactory, session -> {
|
||||
String organizationId = (String) session
|
||||
.createNativeQuery( "select organizations from Company_organizations" )
|
||||
.getSingleResult();
|
||||
assertEquals( "ORG-ACME", organizationId );
|
||||
|
||||
Company company = session.find( Company.class, 1L );
|
||||
|
||||
assertEquals( 1, company.getOrganizations().size() );
|
||||
assertEquals( "ACME" , company.getOrganizations().get( 0 ).getOrganizationId());
|
||||
} );
|
||||
}
|
||||
}
|
|
@ -1,485 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.reflection;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import javax.persistence.AssociationOverrides;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Converts;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.EmbeddedId;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.ExcludeDefaultListeners;
|
||||
import javax.persistence.ExcludeSuperclassListeners;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.IdClass;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.MapKey;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.NamedNativeQueries;
|
||||
import javax.persistence.NamedQueries;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.OrderBy;
|
||||
import javax.persistence.PostLoad;
|
||||
import javax.persistence.PostPersist;
|
||||
import javax.persistence.PrePersist;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.PrimaryKeyJoinColumns;
|
||||
import javax.persistence.SecondaryTable;
|
||||
import javax.persistence.SecondaryTables;
|
||||
import javax.persistence.SequenceGenerator;
|
||||
import javax.persistence.SqlResultSetMappings;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.TableGenerator;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.Transient;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import org.hibernate.annotations.Columns;
|
||||
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
||||
import org.hibernate.internal.util.xml.ErrorLogger;
|
||||
import org.hibernate.internal.util.xml.XMLHelper;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests the legacy {@link JPAOverriddenAnnotationReader},
|
||||
* which will be replaced with {@link org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenAnnotationReader}.
|
||||
* {@link JPAOverriddenAnnotationReader} is still the default implementation,
|
||||
* but we want to switch to {@link org.hibernate.cfg.annotations.reflection.internal.JPAXMLOverriddenAnnotationReader}
|
||||
* as soon as it will be practical.
|
||||
*
|
||||
* @see JPAXMLOverriddenAnnotationReaderTest
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyJPAOverriddenAnnotationReaderTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void testMappedSuperclassAnnotations() throws Exception {
|
||||
XMLContext context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
JPAOverriddenAnnotationReader reader = new JPAOverriddenAnnotationReader( Organization.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertTrue( reader.isAnnotationPresent( MappedSuperclass.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
JPAOverriddenAnnotationReader reader = new JPAOverriddenAnnotationReader( Administration.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Entity.class ) );
|
||||
assertEquals(
|
||||
"Default value in xml entity should not override @Entity.name", "JavaAdministration",
|
||||
reader.getAnnotation( Entity.class ).name()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||
assertEquals( "@Table not overridden", "tbl_admin", reader.getAnnotation( Table.class ).name() );
|
||||
assertEquals( "Default schema not overridden", "myschema", reader.getAnnotation( Table.class ).schema() );
|
||||
assertEquals(
|
||||
"Proper @Table.uniqueConstraints", 2,
|
||||
reader.getAnnotation( Table.class ).uniqueConstraints()[0].columnNames().length
|
||||
);
|
||||
String columnName = reader.getAnnotation( Table.class ).uniqueConstraints()[0].columnNames()[0];
|
||||
assertTrue(
|
||||
"Proper @Table.uniqueConstraints", "firstname".equals( columnName ) || "lastname".equals( columnName )
|
||||
);
|
||||
assertNull( "Both Java and XML used", reader.getAnnotation( SecondaryTable.class ) );
|
||||
assertNotNull( "XML does not work", reader.getAnnotation( SecondaryTables.class ) );
|
||||
SecondaryTable[] tables = reader.getAnnotation( SecondaryTables.class ).value();
|
||||
assertEquals( 1, tables.length );
|
||||
assertEquals( "admin2", tables[0].name() );
|
||||
assertEquals( "unique constraints ignored", 1, tables[0].uniqueConstraints().length );
|
||||
assertEquals( "pk join column ignored", 1, tables[0].pkJoinColumns().length );
|
||||
assertEquals( "pk join column ignored", "admin_id", tables[0].pkJoinColumns()[0].name() );
|
||||
assertNotNull( "Sequence Overriding not working", reader.getAnnotation( SequenceGenerator.class ) );
|
||||
assertEquals(
|
||||
"wrong sequence name", "seqhilo", reader.getAnnotation( SequenceGenerator.class ).sequenceName()
|
||||
);
|
||||
assertEquals( "default fails", 50, reader.getAnnotation( SequenceGenerator.class ).allocationSize() );
|
||||
assertNotNull( "TableOverriding not working", reader.getAnnotation( TableGenerator.class ) );
|
||||
assertEquals( "wrong tble name", "tablehilo", reader.getAnnotation( TableGenerator.class ).table() );
|
||||
assertEquals( "no schema overriding", "myschema", reader.getAnnotation( TableGenerator.class ).schema() );
|
||||
|
||||
reader = new JPAOverriddenAnnotationReader( Match.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||
assertEquals(
|
||||
"Java annotation not taken into account", "matchtable", reader.getAnnotation( Table.class ).name()
|
||||
);
|
||||
assertEquals(
|
||||
"Java annotation not taken into account", "matchschema", reader.getAnnotation( Table.class ).schema()
|
||||
);
|
||||
assertEquals( "Overriding not taken into account", "mycatalog", reader.getAnnotation( Table.class ).catalog() );
|
||||
assertNotNull( "SecondaryTable swallowed", reader.getAnnotation( SecondaryTables.class ) );
|
||||
assertEquals(
|
||||
"Default schema not taken into account", "myschema",
|
||||
reader.getAnnotation( SecondaryTables.class ).value()[0].schema()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( Inheritance.class ) );
|
||||
assertEquals(
|
||||
"inheritance strategy not overriden", InheritanceType.JOINED,
|
||||
reader.getAnnotation( Inheritance.class ).strategy()
|
||||
);
|
||||
assertNotNull( "NamedQuery not overriden", reader.getAnnotation( NamedQueries.class ) );
|
||||
assertEquals( "No deduplication", 3, reader.getAnnotation( NamedQueries.class ).value().length );
|
||||
assertEquals(
|
||||
"deduplication kept the Java version", 1,
|
||||
reader.getAnnotation( NamedQueries.class ).value()[1].hints().length
|
||||
);
|
||||
assertEquals(
|
||||
"org.hibernate.timeout", reader.getAnnotation( NamedQueries.class ).value()[1].hints()[0].name()
|
||||
);
|
||||
assertNotNull( "NamedNativeQuery not overriden", reader.getAnnotation( NamedNativeQueries.class ) );
|
||||
assertEquals( "No deduplication", 3, reader.getAnnotation( NamedNativeQueries.class ).value().length );
|
||||
assertEquals(
|
||||
"deduplication kept the Java version", 1,
|
||||
reader.getAnnotation( NamedNativeQueries.class ).value()[1].hints().length
|
||||
);
|
||||
assertEquals(
|
||||
"org.hibernate.timeout", reader.getAnnotation( NamedNativeQueries.class ).value()[1].hints()[0].name()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( SqlResultSetMappings.class ) );
|
||||
assertEquals(
|
||||
"competitor1Point", reader.getAnnotation( SqlResultSetMappings.class ).value()[0].columns()[0].name()
|
||||
);
|
||||
assertEquals(
|
||||
"competitor1Point",
|
||||
reader.getAnnotation( SqlResultSetMappings.class ).value()[0].entities()[0].fields()[0].column()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( ExcludeSuperclassListeners.class ) );
|
||||
assertNotNull( reader.getAnnotation( ExcludeDefaultListeners.class ) );
|
||||
|
||||
reader = new JPAOverriddenAnnotationReader( Competition.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( MappedSuperclass.class ) );
|
||||
|
||||
reader = new JPAOverriddenAnnotationReader( TennisMatch.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( "Mutualize PKJC into PKJCs", reader.getAnnotation( PrimaryKeyJoinColumn.class ) );
|
||||
assertNotNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
||||
assertEquals(
|
||||
"PrimaryKeyJoinColumn overrden", "id",
|
||||
reader.getAnnotation( PrimaryKeyJoinColumns.class ).value()[0].name()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( AttributeOverrides.class ) );
|
||||
assertEquals( "Wrong deduplication", 3, reader.getAnnotation( AttributeOverrides.class ).value().length );
|
||||
assertEquals(
|
||||
"Wrong priority (XML vs java annotations)", "fld_net",
|
||||
reader.getAnnotation( AttributeOverrides.class ).value()[0].column().name()
|
||||
);
|
||||
assertEquals(
|
||||
"Column mapping", 2, reader.getAnnotation( AttributeOverrides.class ).value()[1].column().scale()
|
||||
);
|
||||
assertEquals(
|
||||
"Column mapping", true, reader.getAnnotation( AttributeOverrides.class ).value()[1].column().unique()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( AssociationOverrides.class ) );
|
||||
assertEquals( "no XML processing", 1, reader.getAnnotation( AssociationOverrides.class ).value().length );
|
||||
assertEquals(
|
||||
"wrong xml processing", "id",
|
||||
reader.getAnnotation( AssociationOverrides.class ).value()[0].joinColumns()[0].referencedColumnName()
|
||||
);
|
||||
|
||||
|
||||
reader = new JPAOverriddenAnnotationReader( SocialSecurityPhysicalAccount.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( IdClass.class ) );
|
||||
assertEquals( "id-class not used", SocialSecurityNumber.class, reader.getAnnotation( IdClass.class ).value() );
|
||||
assertEquals(
|
||||
"discriminator-value not used", "Physical", reader.getAnnotation( DiscriminatorValue.class ).value()
|
||||
);
|
||||
assertNotNull( "discriminator-column not used", reader.getAnnotation( DiscriminatorColumn.class ) );
|
||||
assertEquals(
|
||||
"discriminator-column.name default value broken", "DTYPE",
|
||||
reader.getAnnotation( DiscriminatorColumn.class ).name()
|
||||
);
|
||||
assertEquals(
|
||||
"discriminator-column.length broken", 34, reader.getAnnotation( DiscriminatorColumn.class ).length()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityRelatedAnnotationsMetadataComplete() throws Exception {
|
||||
XMLContext context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
JPAOverriddenAnnotationReader reader = new JPAOverriddenAnnotationReader( Administration.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Entity.class ) );
|
||||
assertEquals(
|
||||
"Metadata complete should ignore java annotations", "", reader.getAnnotation( Entity.class ).name()
|
||||
);
|
||||
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||
assertEquals( "@Table should not be used", "", reader.getAnnotation( Table.class ).name() );
|
||||
assertEquals( "Default schema not overriden", "myschema", reader.getAnnotation( Table.class ).schema() );
|
||||
|
||||
reader = new JPAOverriddenAnnotationReader( Match.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Table.class ) );
|
||||
assertEquals( "@Table should not be used", "", reader.getAnnotation( Table.class ).name() );
|
||||
assertEquals( "Overriding not taken into account", "myschema", reader.getAnnotation( Table.class ).schema() );
|
||||
assertEquals( "Overriding not taken into account", "mycatalog", reader.getAnnotation( Table.class ).catalog() );
|
||||
assertNull( "Ignore Java annotation", reader.getAnnotation( SecondaryTable.class ) );
|
||||
assertNull( "Ignore Java annotation", reader.getAnnotation( SecondaryTables.class ) );
|
||||
assertNull( "Ignore Java annotation", reader.getAnnotation( Inheritance.class ) );
|
||||
assertNull( reader.getAnnotation( NamedQueries.class ) );
|
||||
assertNull( reader.getAnnotation( NamedNativeQueries.class ) );
|
||||
|
||||
reader = new JPAOverriddenAnnotationReader( TennisMatch.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( reader.getAnnotation( PrimaryKeyJoinColumn.class ) );
|
||||
assertNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
||||
|
||||
reader = new JPAOverriddenAnnotationReader( Competition.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( reader.getAnnotation( MappedSuperclass.class ) );
|
||||
|
||||
reader = new JPAOverriddenAnnotationReader( SocialSecurityMoralAccount.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( reader.getAnnotation( IdClass.class ) );
|
||||
assertNull( reader.getAnnotation( DiscriminatorValue.class ) );
|
||||
assertNull( reader.getAnnotation( DiscriminatorColumn.class ) );
|
||||
assertNull( reader.getAnnotation( SequenceGenerator.class ) );
|
||||
assertNull( reader.getAnnotation( TableGenerator.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIdRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
Method method = Administration.class.getDeclaredMethod( "getId" );
|
||||
JPAOverriddenAnnotationReader reader = new JPAOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( reader.getAnnotation( Id.class ) );
|
||||
assertNull( reader.getAnnotation( Column.class ) );
|
||||
Field field = Administration.class.getDeclaredField( "id" );
|
||||
reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Id.class ) );
|
||||
assertNotNull( reader.getAnnotation( GeneratedValue.class ) );
|
||||
assertEquals( GenerationType.SEQUENCE, reader.getAnnotation( GeneratedValue.class ).strategy() );
|
||||
assertEquals( "generator", reader.getAnnotation( GeneratedValue.class ).generator() );
|
||||
assertNotNull( reader.getAnnotation( SequenceGenerator.class ) );
|
||||
assertEquals( "seq", reader.getAnnotation( SequenceGenerator.class ).sequenceName() );
|
||||
assertNotNull( reader.getAnnotation( Columns.class ) );
|
||||
assertEquals( 1, reader.getAnnotation( Columns.class ).columns().length );
|
||||
assertEquals( "fld_id", reader.getAnnotation( Columns.class ).columns()[0].name() );
|
||||
assertNotNull( reader.getAnnotation( Temporal.class ) );
|
||||
assertEquals( TemporalType.DATE, reader.getAnnotation( Temporal.class ).value() );
|
||||
|
||||
context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
method = Administration.class.getDeclaredMethod( "getId" );
|
||||
reader = new JPAOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull(
|
||||
"Default access type when not defined in metadata complete should be property",
|
||||
reader.getAnnotation( Id.class )
|
||||
);
|
||||
field = Administration.class.getDeclaredField( "id" );
|
||||
reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull(
|
||||
"Default access type when not defined in metadata complete should be property",
|
||||
reader.getAnnotation( Id.class )
|
||||
);
|
||||
|
||||
method = BusTrip.class.getDeclaredMethod( "getId" );
|
||||
reader = new JPAOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNull( reader.getAnnotation( EmbeddedId.class ) );
|
||||
field = BusTrip.class.getDeclaredField( "id" );
|
||||
reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( EmbeddedId.class ) );
|
||||
assertNotNull( reader.getAnnotation( AttributeOverrides.class ) );
|
||||
assertEquals( 1, reader.getAnnotation( AttributeOverrides.class ).value().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
Field field = BusTrip.class.getDeclaredField( "status" );
|
||||
JPAOverriddenAnnotationReader reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Enumerated.class ) );
|
||||
assertEquals( EnumType.STRING, reader.getAnnotation( Enumerated.class ).value() );
|
||||
assertEquals( false, reader.getAnnotation( Basic.class ).optional() );
|
||||
field = BusTrip.class.getDeclaredField( "serial" );
|
||||
reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Lob.class ) );
|
||||
assertEquals( "serialbytes", reader.getAnnotation( Columns.class ).columns()[0].name() );
|
||||
field = BusTrip.class.getDeclaredField( "terminusTime" );
|
||||
reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Temporal.class ) );
|
||||
assertEquals( TemporalType.TIMESTAMP, reader.getAnnotation( Temporal.class ).value() );
|
||||
assertEquals( FetchType.LAZY, reader.getAnnotation( Basic.class ).fetch() );
|
||||
|
||||
field = BusTripPk.class.getDeclaredField( "busDriver" );
|
||||
reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.isAnnotationPresent( Basic.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersionRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
Method method = Administration.class.getDeclaredMethod( "getVersion" );
|
||||
JPAOverriddenAnnotationReader reader = new JPAOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Version.class ) );
|
||||
|
||||
Field field = Match.class.getDeclaredField( "version" );
|
||||
assertNotNull( reader.getAnnotation( Version.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransientAndEmbeddedRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Field field = Administration.class.getDeclaredField( "transientField" );
|
||||
JPAOverriddenAnnotationReader reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Transient.class ) );
|
||||
assertNull( reader.getAnnotation( Basic.class ) );
|
||||
|
||||
field = Match.class.getDeclaredField( "playerASSN" );
|
||||
reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( Embedded.class ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssociationRelatedAnnotations() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Field field = Administration.class.getDeclaredField( "defaultBusTrip" );
|
||||
JPAOverriddenAnnotationReader reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( OneToOne.class ) );
|
||||
assertNull( reader.getAnnotation( JoinColumns.class ) );
|
||||
assertNotNull( reader.getAnnotation( PrimaryKeyJoinColumns.class ) );
|
||||
assertEquals( "pk", reader.getAnnotation( PrimaryKeyJoinColumns.class ).value()[0].name() );
|
||||
assertEquals( 5, reader.getAnnotation( OneToOne.class ).cascade().length );
|
||||
assertEquals( FetchType.LAZY, reader.getAnnotation( OneToOne.class ).fetch() );
|
||||
assertEquals( "test", reader.getAnnotation( OneToOne.class ).mappedBy() );
|
||||
|
||||
context = buildContext(
|
||||
"org/hibernate/test/annotations/reflection/metadata-complete.xml"
|
||||
);
|
||||
field = BusTrip.class.getDeclaredField( "players" );
|
||||
reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( OneToMany.class ) );
|
||||
assertNotNull( reader.getAnnotation( JoinColumns.class ) );
|
||||
assertEquals( 2, reader.getAnnotation( JoinColumns.class ).value().length );
|
||||
assertEquals( "driver", reader.getAnnotation( JoinColumns.class ).value()[0].name() );
|
||||
assertNotNull( reader.getAnnotation( MapKey.class ) );
|
||||
assertEquals( "name", reader.getAnnotation( MapKey.class ).name() );
|
||||
|
||||
field = BusTrip.class.getDeclaredField( "roads" );
|
||||
reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( ManyToMany.class ) );
|
||||
assertNotNull( reader.getAnnotation( JoinTable.class ) );
|
||||
assertEquals( "bus_road", reader.getAnnotation( JoinTable.class ).name() );
|
||||
assertEquals( 2, reader.getAnnotation( JoinTable.class ).joinColumns().length );
|
||||
assertEquals( 1, reader.getAnnotation( JoinTable.class ).inverseJoinColumns().length );
|
||||
assertEquals( 2, reader.getAnnotation( JoinTable.class ).uniqueConstraints()[0].columnNames().length );
|
||||
assertNotNull( reader.getAnnotation( OrderBy.class ) );
|
||||
assertEquals( "maxSpeed", reader.getAnnotation( OrderBy.class ).value() );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue(jiraKey = "HHH-11924")
|
||||
public void testElementCollectionConverter() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Field field = Company.class.getDeclaredField( "organizations" );
|
||||
JPAOverriddenAnnotationReader reader = new JPAOverriddenAnnotationReader( field, context, BootstrapContextImpl.INSTANCE );
|
||||
assertNotNull( reader.getAnnotation( ElementCollection.class ) );
|
||||
assertNotNull( reader.getAnnotation( Converts.class ) );
|
||||
assertNotNull( reader.getAnnotation( Converts.class ).value() );
|
||||
assertTrue( reader.getAnnotation( Converts.class ).value().length == 1 );
|
||||
assertEquals(OrganizationConverter.class, reader.getAnnotation( Converts.class ).value()[0].converter());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEntityListeners() throws Exception {
|
||||
XMLContext context = buildContext( "org/hibernate/test/annotations/reflection/orm.xml" );
|
||||
|
||||
Method method = Administration.class.getDeclaredMethod( "calculate" );
|
||||
JPAOverriddenAnnotationReader reader = new JPAOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertTrue( reader.isAnnotationPresent( PrePersist.class ) );
|
||||
|
||||
reader = new JPAOverriddenAnnotationReader( Administration.class, context, BootstrapContextImpl.INSTANCE );
|
||||
assertTrue( reader.isAnnotationPresent( EntityListeners.class ) );
|
||||
assertEquals( 1, reader.getAnnotation( EntityListeners.class ).value().length );
|
||||
assertEquals( LogListener.class, reader.getAnnotation( EntityListeners.class ).value()[0] );
|
||||
|
||||
method = LogListener.class.getDeclaredMethod( "noLog", Object.class );
|
||||
reader = new JPAOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertTrue( reader.isAnnotationPresent( PostLoad.class ) );
|
||||
|
||||
method = LogListener.class.getDeclaredMethod( "log", Object.class );
|
||||
reader = new JPAOverriddenAnnotationReader( method, context, BootstrapContextImpl.INSTANCE );
|
||||
assertTrue( reader.isAnnotationPresent( PrePersist.class ) );
|
||||
assertFalse( reader.isAnnotationPresent( PostPersist.class ) );
|
||||
|
||||
assertEquals( 1, context.getDefaultEntityListeners().size() );
|
||||
assertEquals( OtherLogListener.class.getName(), context.getDefaultEntityListeners().get( 0 ) );
|
||||
}
|
||||
|
||||
private XMLContext buildContext(String ormfile) throws SAXException, DocumentException, IOException {
|
||||
XMLHelper xmlHelper = new XMLHelper();
|
||||
InputStream is = ClassLoaderServiceTestingImpl.INSTANCE.locateResourceStream( ormfile );
|
||||
assertNotNull( "ORM.xml not found: " + ormfile, is );
|
||||
XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
ErrorLogger errorLogger = new ErrorLogger();
|
||||
SAXReader saxReader = xmlHelper.createSAXReader( errorLogger, EJB3DTDEntityResolver.INSTANCE );
|
||||
//saxReader.setValidation( false );
|
||||
try {
|
||||
saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
|
||||
}
|
||||
catch ( SAXNotSupportedException e ) {
|
||||
saxReader.setValidation( false );
|
||||
}
|
||||
org.dom4j.Document doc;
|
||||
try {
|
||||
doc = saxReader.read( new InputSource( new BufferedInputStream( is ) ) );
|
||||
}
|
||||
finally {
|
||||
is.close();
|
||||
}
|
||||
if ( errorLogger.hasErrors() ) {
|
||||
System.out.println( errorLogger.getErrors().get( 0 ) );
|
||||
}
|
||||
assertFalse( errorLogger.hasErrors() );
|
||||
context.addDocument( doc );
|
||||
return context;
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.reflection;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.hibernate.cfg.EJB3DTDEntityResolver;
|
||||
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
||||
import org.hibernate.internal.util.xml.ErrorLogger;
|
||||
import org.hibernate.internal.util.xml.XMLHelper;
|
||||
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXNotSupportedException;
|
||||
|
||||
/**
|
||||
* Tests the legacy {@link XMLContext},
|
||||
* which will be replaced with {@link org.hibernate.cfg.annotations.reflection.internal.XMLContext}.
|
||||
* {@link XMLContext} is still the default implementation,
|
||||
* but we want to switch to {@link org.hibernate.cfg.annotations.reflection.internal.XMLContext}
|
||||
* as soon as it will be practical.
|
||||
*
|
||||
* @see XMLContextTest
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link XMLContext}.
|
||||
*/
|
||||
public class LegacyXMLContextTest {
|
||||
@Test
|
||||
public void testAll() throws Exception {
|
||||
final XMLHelper xmlHelper = new XMLHelper();
|
||||
final XMLContext context = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
|
||||
InputStream is = ClassLoaderServiceTestingImpl.INSTANCE.locateResourceStream(
|
||||
"org/hibernate/test/annotations/reflection/orm.xml"
|
||||
);
|
||||
Assert.assertNotNull( "ORM.xml not found", is );
|
||||
|
||||
final ErrorLogger errorLogger = new ErrorLogger();
|
||||
final SAXReader saxReader = xmlHelper.createSAXReader( errorLogger, EJB3DTDEntityResolver.INSTANCE );
|
||||
|
||||
try {
|
||||
saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
|
||||
}
|
||||
catch ( SAXNotSupportedException e ) {
|
||||
saxReader.setValidation( false );
|
||||
}
|
||||
org.dom4j.Document doc;
|
||||
try {
|
||||
doc = saxReader.read( new InputSource( new BufferedInputStream( is ) ) );
|
||||
}
|
||||
finally {
|
||||
try {
|
||||
is.close();
|
||||
}
|
||||
catch ( IOException ioe ) {
|
||||
//log.warn( "Could not close input stream", ioe );
|
||||
}
|
||||
}
|
||||
Assert.assertFalse( errorLogger.hasErrors() );
|
||||
context.addDocument( doc );
|
||||
}
|
||||
}
|
|
@ -1,716 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.AssociationOverride;
|
||||
import javax.persistence.AssociationOverrides;
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.Lob;
|
||||
import javax.persistence.MapKey;
|
||||
import javax.persistence.MapKeyClass;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.MapKeyEnumerated;
|
||||
import javax.persistence.MapKeyJoinColumn;
|
||||
import javax.persistence.MapKeyJoinColumns;
|
||||
import javax.persistence.MapKeyTemporal;
|
||||
import javax.persistence.OrderBy;
|
||||
import javax.persistence.OrderColumn;
|
||||
import javax.persistence.Temporal;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlElementCollectionTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlElementCollectionTest extends LegacyEjb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm1.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( Column.class );
|
||||
assertAnnotationNotPresent( Temporal.class );
|
||||
assertAnnotationNotPresent( Enumerated.class );
|
||||
assertAnnotationNotPresent( Lob.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationNotPresent( AttributeOverrides.class );
|
||||
assertAnnotationNotPresent( AssociationOverride.class );
|
||||
assertAnnotationNotPresent( AssociationOverrides.class );
|
||||
assertAnnotationNotPresent( CollectionTable.class );
|
||||
assertAnnotationNotPresent( Access.class );
|
||||
ElementCollection relAnno = reader.getAnnotation( ElementCollection.class );
|
||||
assertEquals( FetchType.LAZY, relAnno.fetch() );
|
||||
assertEquals( void.class, relAnno.targetClass() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderBy() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm2.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertEquals(
|
||||
"col1 ASC, col2 DESC", reader.getAnnotation( OrderBy.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm3.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "", orderColumnAnno.name() );
|
||||
assertTrue( orderColumnAnno.insertable() );
|
||||
assertTrue( orderColumnAnno.nullable() );
|
||||
assertTrue( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm4.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "int", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "col1", orderColumnAnno.name() );
|
||||
assertFalse( orderColumnAnno.insertable() );
|
||||
assertFalse( orderColumnAnno.nullable() );
|
||||
assertFalse( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm5.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm6.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyClass() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm7.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
Entity2.class, reader.getAnnotation( MapKeyClass.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm8.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
TemporalType.DATE, reader.getAnnotation(
|
||||
MapKeyTemporal.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm9.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
EnumType.STRING, reader.getAnnotation(
|
||||
MapKeyEnumerated.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key attribute override, we still wrap it with
|
||||
* an AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm10.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 1, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm11.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "", overrides[0].column().name() );
|
||||
assertFalse( overrides[0].column().unique() );
|
||||
assertTrue( overrides[0].column().nullable() );
|
||||
assertTrue( overrides[0].column().insertable() );
|
||||
assertTrue( overrides[0].column().updatable() );
|
||||
assertEquals( "", overrides[0].column().columnDefinition() );
|
||||
assertEquals( "", overrides[0].column().table() );
|
||||
assertEquals( 255, overrides[0].column().length() );
|
||||
assertEquals( 0, overrides[0].column().precision() );
|
||||
assertEquals( 0, overrides[0].column().scale() );
|
||||
assertEquals( "field2", overrides[1].name() );
|
||||
assertEquals( "col1", overrides[1].column().name() );
|
||||
assertTrue( overrides[1].column().unique() );
|
||||
assertFalse( overrides[1].column().nullable() );
|
||||
assertFalse( overrides[1].column().insertable() );
|
||||
assertFalse( overrides[1].column().updatable() );
|
||||
assertEquals( "int", overrides[1].column().columnDefinition() );
|
||||
assertEquals( "table1", overrides[1].column().table() );
|
||||
assertEquals( 50, overrides[1].column().length() );
|
||||
assertEquals( 2, overrides[1].column().precision() );
|
||||
assertEquals( 1, overrides[1].column().scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm12.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "", keyColAnno.columnDefinition() );
|
||||
assertEquals( "", keyColAnno.name() );
|
||||
assertEquals( "", keyColAnno.table() );
|
||||
assertFalse( keyColAnno.nullable() );
|
||||
assertTrue( keyColAnno.insertable() );
|
||||
assertFalse( keyColAnno.unique() );
|
||||
assertTrue( keyColAnno.updatable() );
|
||||
assertEquals( 255, keyColAnno.length() );
|
||||
assertEquals( 0, keyColAnno.precision() );
|
||||
assertEquals( 0, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm13.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "int", keyColAnno.columnDefinition() );
|
||||
assertEquals( "col1", keyColAnno.name() );
|
||||
assertEquals( "table1", keyColAnno.table() );
|
||||
assertTrue( keyColAnno.nullable() );
|
||||
assertFalse( keyColAnno.insertable() );
|
||||
assertTrue( keyColAnno.unique() );
|
||||
assertFalse( keyColAnno.updatable() );
|
||||
assertEquals( 50, keyColAnno.length() );
|
||||
assertEquals( 2, keyColAnno.precision() );
|
||||
assertEquals( 1, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key join column, we still wrap it with a
|
||||
* MapKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm14.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm15.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertFalse( joinColumns[0].nullable() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
assertTrue( joinColumns[1].nullable() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm16.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( Column.class );
|
||||
Column column = reader.getAnnotation( Column.class );
|
||||
assertEquals( "", column.name() );
|
||||
assertFalse( column.unique() );
|
||||
assertTrue( column.nullable() );
|
||||
assertTrue( column.insertable() );
|
||||
assertTrue( column.updatable() );
|
||||
assertEquals( "", column.columnDefinition() );
|
||||
assertEquals( "", column.table() );
|
||||
assertEquals( 255, column.length() );
|
||||
assertEquals( 0, column.precision() );
|
||||
assertEquals( 0, column.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm17.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( Column.class );
|
||||
Column column = reader.getAnnotation( Column.class );
|
||||
assertEquals( "col1", column.name() );
|
||||
assertTrue( column.unique() );
|
||||
assertFalse( column.nullable() );
|
||||
assertFalse( column.insertable() );
|
||||
assertFalse( column.updatable() );
|
||||
assertEquals( "int", column.columnDefinition() );
|
||||
assertEquals( "table1", column.table() );
|
||||
assertEquals( 50, column.length() );
|
||||
assertEquals( 2, column.precision() );
|
||||
assertEquals( 1, column.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm18.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( Temporal.class );
|
||||
assertAnnotationNotPresent( Enumerated.class );
|
||||
assertAnnotationNotPresent( Lob.class );
|
||||
assertEquals(
|
||||
TemporalType.DATE, reader.getAnnotation(
|
||||
Temporal.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm19.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( Temporal.class );
|
||||
assertAnnotationPresent( Enumerated.class );
|
||||
assertAnnotationNotPresent( Lob.class );
|
||||
assertEquals(
|
||||
EnumType.STRING, reader.getAnnotation(
|
||||
Enumerated.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLob() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm20.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( Temporal.class );
|
||||
assertAnnotationNotPresent( Enumerated.class );
|
||||
assertAnnotationPresent( Lob.class );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single attribute override, we still wrap it with an
|
||||
* AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm21.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 1, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm22.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "", overrides[0].column().name() );
|
||||
assertFalse( overrides[0].column().unique() );
|
||||
assertTrue( overrides[0].column().nullable() );
|
||||
assertTrue( overrides[0].column().insertable() );
|
||||
assertTrue( overrides[0].column().updatable() );
|
||||
assertEquals( "", overrides[0].column().columnDefinition() );
|
||||
assertEquals( "", overrides[0].column().table() );
|
||||
assertEquals( 255, overrides[0].column().length() );
|
||||
assertEquals( 0, overrides[0].column().precision() );
|
||||
assertEquals( 0, overrides[0].column().scale() );
|
||||
assertEquals( "field2", overrides[1].name() );
|
||||
assertEquals( "col1", overrides[1].column().name() );
|
||||
assertTrue( overrides[1].column().unique() );
|
||||
assertFalse( overrides[1].column().nullable() );
|
||||
assertFalse( overrides[1].column().insertable() );
|
||||
assertFalse( overrides[1].column().updatable() );
|
||||
assertEquals( "int", overrides[1].column().columnDefinition() );
|
||||
assertEquals( "table1", overrides[1].column().table() );
|
||||
assertEquals( 50, overrides[1].column().length() );
|
||||
assertEquals( 2, overrides[1].column().precision() );
|
||||
assertEquals( 1, overrides[1].column().scale() );
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that map-key-attribute-override and attribute-override elements
|
||||
* both end up in the AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testMixedAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm23.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "col1", overrides[0].column().name() );
|
||||
assertEquals( "field2", overrides[1].name() );
|
||||
assertEquals( "col2", overrides[1].column().name() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single association override, we still wrap it with an
|
||||
* AssociationOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleAssociationOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm24.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( AssociationOverride.class );
|
||||
assertAnnotationPresent( AssociationOverrides.class );
|
||||
AssociationOverrides overridesAnno = reader.getAnnotation( AssociationOverrides.class );
|
||||
AssociationOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 1, overrides.length );
|
||||
assertEquals( "association1", overrides[0].name() );
|
||||
assertEquals( 0, overrides[0].joinColumns().length );
|
||||
assertEquals( "", overrides[0].joinTable().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleAssociationOverridesJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm25.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( AssociationOverride.class );
|
||||
assertAnnotationPresent( AssociationOverrides.class );
|
||||
AssociationOverrides overridesAnno = reader.getAnnotation( AssociationOverrides.class );
|
||||
AssociationOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
//First, an association using join table
|
||||
assertEquals( "association1", overrides[0].name() );
|
||||
assertEquals( 0, overrides[0].joinColumns().length );
|
||||
|
||||
JoinTable joinTableAnno = overrides[0].joinTable();
|
||||
assertEquals( "catalog1", joinTableAnno.catalog() );
|
||||
assertEquals( "table1", joinTableAnno.name() );
|
||||
assertEquals( "schema1", joinTableAnno.schema() );
|
||||
|
||||
//JoinColumns
|
||||
JoinColumn[] joinColumns = joinTableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
//InverseJoinColumns
|
||||
JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
|
||||
assertEquals( 2, inverseJoinColumns.length );
|
||||
assertEquals( "", inverseJoinColumns[0].name() );
|
||||
assertEquals( "", inverseJoinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", inverseJoinColumns[0].table() );
|
||||
assertEquals( "", inverseJoinColumns[0].columnDefinition() );
|
||||
assertTrue( inverseJoinColumns[0].insertable() );
|
||||
assertTrue( inverseJoinColumns[0].updatable() );
|
||||
assertTrue( inverseJoinColumns[0].nullable() );
|
||||
assertFalse( inverseJoinColumns[0].unique() );
|
||||
assertEquals( "col3", inverseJoinColumns[1].name() );
|
||||
assertEquals( "col4", inverseJoinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table3", inverseJoinColumns[1].table() );
|
||||
assertEquals( "int", inverseJoinColumns[1].columnDefinition() );
|
||||
assertFalse( inverseJoinColumns[1].insertable() );
|
||||
assertFalse( inverseJoinColumns[1].updatable() );
|
||||
assertFalse( inverseJoinColumns[1].nullable() );
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
//UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col6", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
|
||||
//Second, an association using join columns
|
||||
assertEquals( "association2", overrides[1].name() );
|
||||
|
||||
//JoinColumns
|
||||
joinColumns = overrides[1].joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col8", joinColumns[1].name() );
|
||||
assertEquals( "col9", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table4", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollectionTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm26.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( CollectionTable.class );
|
||||
CollectionTable tableAnno = reader.getAnnotation( CollectionTable.class );
|
||||
assertEquals( "", tableAnno.name() );
|
||||
assertEquals( "", tableAnno.catalog() );
|
||||
assertEquals( "", tableAnno.schema() );
|
||||
assertEquals( 0, tableAnno.joinColumns().length );
|
||||
assertEquals( 0, tableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollectionTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "element-collection.orm27.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationPresent( CollectionTable.class );
|
||||
CollectionTable tableAnno = reader.getAnnotation( CollectionTable.class );
|
||||
assertEquals( "table1", tableAnno.name() );
|
||||
assertEquals( "catalog1", tableAnno.catalog() );
|
||||
assertEquals( "schema1", tableAnno.schema() );
|
||||
|
||||
//JoinColumns
|
||||
JoinColumn[] joinColumns = tableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
//UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = tableAnno.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col3", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col4", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col5", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "element-collection.orm28.xml" );
|
||||
assertAnnotationPresent( ElementCollection.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( Column.class );
|
||||
assertAnnotationNotPresent( Temporal.class );
|
||||
assertAnnotationNotPresent( Enumerated.class );
|
||||
assertAnnotationNotPresent( Lob.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationNotPresent( AttributeOverrides.class );
|
||||
assertAnnotationNotPresent( AssociationOverride.class );
|
||||
assertAnnotationNotPresent( AssociationOverrides.class );
|
||||
assertAnnotationNotPresent( CollectionTable.class );
|
||||
assertAnnotationPresent( Access.class );
|
||||
ElementCollection relAnno = reader.getAnnotation( ElementCollection.class );
|
||||
assertEquals( FetchType.EAGER, relAnno.fetch() );
|
||||
assertEquals( Entity3.class, relAnno.targetClass() );
|
||||
assertEquals(
|
||||
AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,508 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToMany;
|
||||
import javax.persistence.MapKey;
|
||||
import javax.persistence.MapKeyClass;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.MapKeyEnumerated;
|
||||
import javax.persistence.MapKeyJoinColumn;
|
||||
import javax.persistence.MapKeyJoinColumns;
|
||||
import javax.persistence.MapKeyTemporal;
|
||||
import javax.persistence.OrderBy;
|
||||
import javax.persistence.OrderColumn;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlManyToManyTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlManyToManyTest extends LegacyEjb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm1.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( Access.class );
|
||||
ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.LAZY, relAnno.fetch() );
|
||||
assertEquals( "", relAnno.mappedBy() );
|
||||
assertEquals( void.class, relAnno.targetEntity() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderBy() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm2.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertEquals(
|
||||
"col1 ASC, col2 DESC", reader.getAnnotation( OrderBy.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm3.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "", orderColumnAnno.name() );
|
||||
assertTrue( orderColumnAnno.insertable() );
|
||||
assertTrue( orderColumnAnno.nullable() );
|
||||
assertTrue( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm4.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "int", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "col1", orderColumnAnno.name() );
|
||||
assertFalse( orderColumnAnno.insertable() );
|
||||
assertFalse( orderColumnAnno.nullable() );
|
||||
assertFalse( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm5.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm6.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyClass() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm7.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
Entity2.class, reader.getAnnotation( MapKeyClass.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm8.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
TemporalType.DATE, reader.getAnnotation(
|
||||
MapKeyTemporal.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm9.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
EnumType.STRING, reader.getAnnotation(
|
||||
MapKeyEnumerated.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key attribute override, we still wrap it with
|
||||
* an AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm10.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 1, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm11.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "", overrides[0].column().name() );
|
||||
assertFalse( overrides[0].column().unique() );
|
||||
assertTrue( overrides[0].column().nullable() );
|
||||
assertTrue( overrides[0].column().insertable() );
|
||||
assertTrue( overrides[0].column().updatable() );
|
||||
assertEquals( "", overrides[0].column().columnDefinition() );
|
||||
assertEquals( "", overrides[0].column().table() );
|
||||
assertEquals( 255, overrides[0].column().length() );
|
||||
assertEquals( 0, overrides[0].column().precision() );
|
||||
assertEquals( 0, overrides[0].column().scale() );
|
||||
assertEquals( "field2", overrides[1].name() );
|
||||
assertEquals( "col1", overrides[1].column().name() );
|
||||
assertTrue( overrides[1].column().unique() );
|
||||
assertFalse( overrides[1].column().nullable() );
|
||||
assertFalse( overrides[1].column().insertable() );
|
||||
assertFalse( overrides[1].column().updatable() );
|
||||
assertEquals( "int", overrides[1].column().columnDefinition() );
|
||||
assertEquals( "table1", overrides[1].column().table() );
|
||||
assertEquals( 50, overrides[1].column().length() );
|
||||
assertEquals( 2, overrides[1].column().precision() );
|
||||
assertEquals( 1, overrides[1].column().scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm12.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "", keyColAnno.columnDefinition() );
|
||||
assertEquals( "", keyColAnno.name() );
|
||||
assertEquals( "", keyColAnno.table() );
|
||||
assertFalse( keyColAnno.nullable() );
|
||||
assertTrue( keyColAnno.insertable() );
|
||||
assertFalse( keyColAnno.unique() );
|
||||
assertTrue( keyColAnno.updatable() );
|
||||
assertEquals( 255, keyColAnno.length() );
|
||||
assertEquals( 0, keyColAnno.precision() );
|
||||
assertEquals( 0, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm13.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "int", keyColAnno.columnDefinition() );
|
||||
assertEquals( "col1", keyColAnno.name() );
|
||||
assertEquals( "table1", keyColAnno.table() );
|
||||
assertTrue( keyColAnno.nullable() );
|
||||
assertFalse( keyColAnno.insertable() );
|
||||
assertTrue( keyColAnno.unique() );
|
||||
assertFalse( keyColAnno.updatable() );
|
||||
assertEquals( 50, keyColAnno.length() );
|
||||
assertEquals( 2, keyColAnno.precision() );
|
||||
assertEquals( 1, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key join column, we still wrap it with a
|
||||
* MapKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm14.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "many-to-many.orm15.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertFalse( joinColumns[0].nullable() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
assertTrue( joinColumns[1].nullable() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm16.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "", joinTableAnno.catalog() );
|
||||
assertEquals( "", joinTableAnno.name() );
|
||||
assertEquals( "", joinTableAnno.schema() );
|
||||
assertEquals( 0, joinTableAnno.joinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.inverseJoinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm17.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "cat1", joinTableAnno.catalog() );
|
||||
assertEquals( "table1", joinTableAnno.name() );
|
||||
assertEquals( "schema1", joinTableAnno.schema() );
|
||||
|
||||
// JoinColumns
|
||||
JoinColumn[] joinColumns = joinTableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
// InverseJoinColumns
|
||||
JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
|
||||
assertEquals( 2, inverseJoinColumns.length );
|
||||
assertEquals( "", inverseJoinColumns[0].name() );
|
||||
assertEquals( "", inverseJoinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", inverseJoinColumns[0].table() );
|
||||
assertEquals( "", inverseJoinColumns[0].columnDefinition() );
|
||||
assertTrue( inverseJoinColumns[0].insertable() );
|
||||
assertTrue( inverseJoinColumns[0].updatable() );
|
||||
assertTrue( inverseJoinColumns[0].nullable() );
|
||||
assertFalse( inverseJoinColumns[0].unique() );
|
||||
assertEquals( "col3", inverseJoinColumns[1].name() );
|
||||
assertEquals( "col4", inverseJoinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table3", inverseJoinColumns[1].table() );
|
||||
assertEquals( "int", inverseJoinColumns[1].columnDefinition() );
|
||||
assertFalse( inverseJoinColumns[1].insertable() );
|
||||
assertFalse( inverseJoinColumns[1].updatable() );
|
||||
assertFalse( inverseJoinColumns[1].nullable() );
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
// UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col6", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm18.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
|
||||
assertEquals( 1, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm19.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
|
||||
assertEquals( 4, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[3] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that it doesn't break the handler when {@link CascadeType#ALL}
|
||||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm20.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
|
||||
assertEquals( 6, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.MERGE, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[3] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[4] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "many-to-many.orm21.xml" );
|
||||
assertAnnotationPresent( ManyToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationPresent( Access.class );
|
||||
ManyToMany relAnno = reader.getAnnotation( ManyToMany.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.EAGER, relAnno.fetch() );
|
||||
assertEquals( "field2", relAnno.mappedBy() );
|
||||
assertEquals( Entity3.class, relAnno.targetEntity() );
|
||||
assertEquals(
|
||||
AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,245 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MapsId;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlManyToOneTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlManyToOneTest extends LegacyEjb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoJoins() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm1.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( Id.class );
|
||||
assertAnnotationNotPresent( MapsId.class );
|
||||
assertAnnotationNotPresent( Access.class );
|
||||
ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.EAGER, relAnno.fetch() );
|
||||
assertTrue( relAnno.optional() );
|
||||
assertEquals( void.class, relAnno.targetEntity() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single join column, we still wrap it with a JoinColumns
|
||||
* annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm2.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
assertEquals( "col2", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[0].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleJoinColumns() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm3.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm4.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "", joinTableAnno.catalog() );
|
||||
assertEquals( "", joinTableAnno.name() );
|
||||
assertEquals( "", joinTableAnno.schema() );
|
||||
assertEquals( 0, joinTableAnno.joinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.inverseJoinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm5.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "cat1", joinTableAnno.catalog() );
|
||||
assertEquals( "table1", joinTableAnno.name() );
|
||||
assertEquals( "schema1", joinTableAnno.schema() );
|
||||
|
||||
// JoinColumns
|
||||
JoinColumn[] joinColumns = joinTableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
// InverseJoinColumns
|
||||
JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
|
||||
assertEquals( 2, inverseJoinColumns.length );
|
||||
assertEquals( "", inverseJoinColumns[0].name() );
|
||||
assertEquals( "", inverseJoinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", inverseJoinColumns[0].table() );
|
||||
assertEquals( "", inverseJoinColumns[0].columnDefinition() );
|
||||
assertTrue( inverseJoinColumns[0].insertable() );
|
||||
assertTrue( inverseJoinColumns[0].updatable() );
|
||||
assertTrue( inverseJoinColumns[0].nullable() );
|
||||
assertFalse( inverseJoinColumns[0].unique() );
|
||||
assertEquals( "col3", inverseJoinColumns[1].name() );
|
||||
assertEquals( "col4", inverseJoinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table3", inverseJoinColumns[1].table() );
|
||||
assertEquals( "int", inverseJoinColumns[1].columnDefinition() );
|
||||
assertFalse( inverseJoinColumns[1].insertable() );
|
||||
assertFalse( inverseJoinColumns[1].updatable() );
|
||||
assertFalse( inverseJoinColumns[1].nullable() );
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
// UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col6", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm6.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationPresent( Id.class );
|
||||
assertAnnotationPresent( MapsId.class );
|
||||
assertAnnotationPresent( Access.class );
|
||||
ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.LAZY, relAnno.fetch() );
|
||||
assertFalse( relAnno.optional() );
|
||||
assertEquals( Entity3.class, relAnno.targetEntity() );
|
||||
assertEquals( "col1", reader.getAnnotation( MapsId.class ).value() );
|
||||
assertEquals(
|
||||
AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm7.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
|
||||
assertEquals( 1, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm8.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
|
||||
assertEquals( 4, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[3] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that it doesn't break the handler when {@link CascadeType#ALL}
|
||||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "many-to-one.orm9.xml" );
|
||||
assertAnnotationPresent( ManyToOne.class );
|
||||
ManyToOne relAnno = reader.getAnnotation( ManyToOne.class );
|
||||
assertEquals( 6, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.MERGE, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[3] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[4] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||
}
|
||||
|
||||
}
|
|
@ -1,561 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.AttributeOverride;
|
||||
import javax.persistence.AttributeOverrides;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.MapKey;
|
||||
import javax.persistence.MapKeyClass;
|
||||
import javax.persistence.MapKeyColumn;
|
||||
import javax.persistence.MapKeyEnumerated;
|
||||
import javax.persistence.MapKeyJoinColumn;
|
||||
import javax.persistence.MapKeyJoinColumns;
|
||||
import javax.persistence.MapKeyTemporal;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OrderBy;
|
||||
import javax.persistence.OrderColumn;
|
||||
import javax.persistence.TemporalType;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlOneToManyTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlOneToManyTest extends LegacyEjb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm1.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( Access.class );
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.LAZY, relAnno.fetch() );
|
||||
assertEquals( "", relAnno.mappedBy() );
|
||||
assertFalse( relAnno.orphanRemoval() );
|
||||
assertEquals( void.class, relAnno.targetEntity() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderBy() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm2.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertEquals(
|
||||
"col1 ASC, col2 DESC", reader.getAnnotation( OrderBy.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm3.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "", orderColumnAnno.name() );
|
||||
assertTrue( orderColumnAnno.insertable() );
|
||||
assertTrue( orderColumnAnno.nullable() );
|
||||
assertTrue( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm4.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationPresent( OrderColumn.class );
|
||||
OrderColumn orderColumnAnno = reader.getAnnotation( OrderColumn.class );
|
||||
assertEquals( "int", orderColumnAnno.columnDefinition() );
|
||||
assertEquals( "col1", orderColumnAnno.name() );
|
||||
assertFalse( orderColumnAnno.insertable() );
|
||||
assertFalse( orderColumnAnno.nullable() );
|
||||
assertFalse( orderColumnAnno.updatable() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm5.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm6.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals( "field2", reader.getAnnotation( MapKey.class ).name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyClass() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm7.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
Entity2.class, reader.getAnnotation( MapKeyClass.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyTemporal() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm8.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
TemporalType.DATE, reader.getAnnotation(
|
||||
MapKeyTemporal.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyEnumerated() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm9.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertEquals(
|
||||
EnumType.STRING, reader.getAnnotation(
|
||||
MapKeyEnumerated.class
|
||||
).value()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key attribute override, we still wrap it with
|
||||
* an AttributeOverrides annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyAttributeOverride() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm10.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 1, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "col1", overrides[0].column().name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyAttributeOverrides() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm11.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( AttributeOverride.class );
|
||||
assertAnnotationPresent( AttributeOverrides.class );
|
||||
AttributeOverrides overridesAnno = reader
|
||||
.getAnnotation( AttributeOverrides.class );
|
||||
AttributeOverride[] overrides = overridesAnno.value();
|
||||
assertEquals( 2, overrides.length );
|
||||
assertEquals( "field1", overrides[0].name() );
|
||||
assertEquals( "", overrides[0].column().name() );
|
||||
assertFalse( overrides[0].column().unique() );
|
||||
assertTrue( overrides[0].column().nullable() );
|
||||
assertTrue( overrides[0].column().insertable() );
|
||||
assertTrue( overrides[0].column().updatable() );
|
||||
assertEquals( "", overrides[0].column().columnDefinition() );
|
||||
assertEquals( "", overrides[0].column().table() );
|
||||
assertEquals( 255, overrides[0].column().length() );
|
||||
assertEquals( 0, overrides[0].column().precision() );
|
||||
assertEquals( 0, overrides[0].column().scale() );
|
||||
assertEquals( "field2", overrides[1].name() );
|
||||
assertEquals( "col1", overrides[1].column().name() );
|
||||
assertTrue( overrides[1].column().unique() );
|
||||
assertFalse( overrides[1].column().nullable() );
|
||||
assertFalse( overrides[1].column().insertable() );
|
||||
assertFalse( overrides[1].column().updatable() );
|
||||
assertEquals( "int", overrides[1].column().columnDefinition() );
|
||||
assertEquals( "table1", overrides[1].column().table() );
|
||||
assertEquals( 50, overrides[1].column().length() );
|
||||
assertEquals( 2, overrides[1].column().precision() );
|
||||
assertEquals( 1, overrides[1].column().scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnNoAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm12.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "", keyColAnno.columnDefinition() );
|
||||
assertEquals( "", keyColAnno.name() );
|
||||
assertEquals( "", keyColAnno.table() );
|
||||
assertFalse( keyColAnno.nullable() );
|
||||
assertTrue( keyColAnno.insertable() );
|
||||
assertFalse( keyColAnno.unique() );
|
||||
assertTrue( keyColAnno.updatable() );
|
||||
assertEquals( 255, keyColAnno.length() );
|
||||
assertEquals( 0, keyColAnno.precision() );
|
||||
assertEquals( 0, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMapKeyColumnAllAttributes() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm13.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyColumn keyColAnno = reader.getAnnotation( MapKeyColumn.class );
|
||||
assertEquals( "int", keyColAnno.columnDefinition() );
|
||||
assertEquals( "col1", keyColAnno.name() );
|
||||
assertEquals( "table1", keyColAnno.table() );
|
||||
assertTrue( keyColAnno.nullable() );
|
||||
assertFalse( keyColAnno.insertable() );
|
||||
assertTrue( keyColAnno.unique() );
|
||||
assertFalse( keyColAnno.updatable() );
|
||||
assertEquals( 50, keyColAnno.length() );
|
||||
assertEquals( 2, keyColAnno.precision() );
|
||||
assertEquals( 1, keyColAnno.scale() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single map key join column, we still wrap it with a
|
||||
* MapKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleMapKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm14.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleMapKeyJoinColumns() throws Exception {
|
||||
reader = getReader( Entity3.class, "field1", "one-to-many.orm15.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
MapKeyJoinColumns joinColumnsAnno = reader
|
||||
.getAnnotation( MapKeyJoinColumns.class );
|
||||
MapKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertFalse( joinColumns[0].nullable() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
assertTrue( joinColumns[1].nullable() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm16.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "", joinTableAnno.catalog() );
|
||||
assertEquals( "", joinTableAnno.name() );
|
||||
assertEquals( "", joinTableAnno.schema() );
|
||||
assertEquals( 0, joinTableAnno.joinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.inverseJoinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm17.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "cat1", joinTableAnno.catalog() );
|
||||
assertEquals( "table1", joinTableAnno.name() );
|
||||
assertEquals( "schema1", joinTableAnno.schema() );
|
||||
|
||||
// JoinColumns
|
||||
JoinColumn[] joinColumns = joinTableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
// InverseJoinColumns
|
||||
JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
|
||||
assertEquals( 2, inverseJoinColumns.length );
|
||||
assertEquals( "", inverseJoinColumns[0].name() );
|
||||
assertEquals( "", inverseJoinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", inverseJoinColumns[0].table() );
|
||||
assertEquals( "", inverseJoinColumns[0].columnDefinition() );
|
||||
assertTrue( inverseJoinColumns[0].insertable() );
|
||||
assertTrue( inverseJoinColumns[0].updatable() );
|
||||
assertTrue( inverseJoinColumns[0].nullable() );
|
||||
assertFalse( inverseJoinColumns[0].unique() );
|
||||
assertEquals( "col3", inverseJoinColumns[1].name() );
|
||||
assertEquals( "col4", inverseJoinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table3", inverseJoinColumns[1].table() );
|
||||
assertEquals( "int", inverseJoinColumns[1].columnDefinition() );
|
||||
assertFalse( inverseJoinColumns[1].insertable() );
|
||||
assertFalse( inverseJoinColumns[1].updatable() );
|
||||
assertFalse( inverseJoinColumns[1].nullable() );
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
// UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col6", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single join column, we still wrap it with a JoinColumns
|
||||
* annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleJoinColumn() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm18.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
assertEquals( "col2", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[0].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleJoinColumns() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm19.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm20.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 1, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm21.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 4, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[3] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that it doesn't break the handler when {@link CascadeType#ALL}
|
||||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm22.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 6, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.MERGE, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[3] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[4] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity2.class, "field1", "one-to-many.orm23.xml" );
|
||||
assertAnnotationPresent( OneToMany.class );
|
||||
assertAnnotationNotPresent( OrderBy.class );
|
||||
assertAnnotationNotPresent( OrderColumn.class );
|
||||
assertAnnotationNotPresent( MapKey.class );
|
||||
assertAnnotationNotPresent( MapKeyClass.class );
|
||||
assertAnnotationNotPresent( MapKeyTemporal.class );
|
||||
assertAnnotationNotPresent( MapKeyEnumerated.class );
|
||||
assertAnnotationNotPresent( MapKeyColumn.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( MapKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( Access.class );
|
||||
OneToMany relAnno = reader.getAnnotation( OneToMany.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.EAGER, relAnno.fetch() );
|
||||
assertEquals( "field2", relAnno.mappedBy() );
|
||||
assertTrue( relAnno.orphanRemoval() );
|
||||
assertEquals( Entity3.class, relAnno.targetEntity() );
|
||||
assertEquals(
|
||||
AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,309 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.xml.ejb3;
|
||||
|
||||
import javax.persistence.Access;
|
||||
import javax.persistence.AccessType;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.JoinColumns;
|
||||
import javax.persistence.JoinTable;
|
||||
import javax.persistence.MapsId;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.PrimaryKeyJoinColumn;
|
||||
import javax.persistence.PrimaryKeyJoinColumns;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlOneToOneTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlOneToOneTest extends LegacyEjb3XmlTestCase {
|
||||
@Test
|
||||
public void testNoChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm1.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( MapsId.class );
|
||||
assertAnnotationNotPresent( Id.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( Access.class );
|
||||
OneToOne relAnno = reader.getAnnotation( OneToOne.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.EAGER, relAnno.fetch() );
|
||||
assertEquals( "", relAnno.mappedBy() );
|
||||
assertTrue( relAnno.optional() );
|
||||
assertFalse( relAnno.orphanRemoval() );
|
||||
assertEquals( void.class, relAnno.targetEntity() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single primary key join column, we still wrap it with
|
||||
* a PrimaryKeyJoinColumns annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSinglePrimaryKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm2.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationPresent( PrimaryKeyJoinColumns.class );
|
||||
PrimaryKeyJoinColumns joinColumnsAnno =
|
||||
reader.getAnnotation( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
PrimaryKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
assertEquals( "col2", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "int", joinColumns[0].columnDefinition() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultiplePrimaryKeyJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm3.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
PrimaryKeyJoinColumns joinColumnsAnno =
|
||||
reader.getAnnotation( PrimaryKeyJoinColumns.class );
|
||||
PrimaryKeyJoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
}
|
||||
|
||||
/**
|
||||
* When there's a single join column, we still wrap it with a JoinColumns
|
||||
* annotation.
|
||||
*/
|
||||
@Test
|
||||
public void testSingleJoinColumn() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm4.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 1, joinColumns.length );
|
||||
assertEquals( "col1", joinColumns[0].name() );
|
||||
assertEquals( "col2", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[0].table() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleJoinColumns() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm5.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
JoinColumns joinColumnsAnno = reader.getAnnotation( JoinColumns.class );
|
||||
JoinColumn[] joinColumns = joinColumnsAnno.value();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table1", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableNoChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm6.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "", joinTableAnno.catalog() );
|
||||
assertEquals( "", joinTableAnno.name() );
|
||||
assertEquals( "", joinTableAnno.schema() );
|
||||
assertEquals( 0, joinTableAnno.joinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.inverseJoinColumns().length );
|
||||
assertEquals( 0, joinTableAnno.uniqueConstraints().length );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJoinTableAllChildren() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm7.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationPresent( JoinTable.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
JoinTable joinTableAnno = reader.getAnnotation( JoinTable.class );
|
||||
assertEquals( "cat1", joinTableAnno.catalog() );
|
||||
assertEquals( "table1", joinTableAnno.name() );
|
||||
assertEquals( "schema1", joinTableAnno.schema() );
|
||||
|
||||
// JoinColumns
|
||||
JoinColumn[] joinColumns = joinTableAnno.joinColumns();
|
||||
assertEquals( 2, joinColumns.length );
|
||||
assertEquals( "", joinColumns[0].name() );
|
||||
assertEquals( "", joinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", joinColumns[0].table() );
|
||||
assertEquals( "", joinColumns[0].columnDefinition() );
|
||||
assertTrue( joinColumns[0].insertable() );
|
||||
assertTrue( joinColumns[0].updatable() );
|
||||
assertTrue( joinColumns[0].nullable() );
|
||||
assertFalse( joinColumns[0].unique() );
|
||||
assertEquals( "col1", joinColumns[1].name() );
|
||||
assertEquals( "col2", joinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table2", joinColumns[1].table() );
|
||||
assertEquals( "int", joinColumns[1].columnDefinition() );
|
||||
assertFalse( joinColumns[1].insertable() );
|
||||
assertFalse( joinColumns[1].updatable() );
|
||||
assertFalse( joinColumns[1].nullable() );
|
||||
assertTrue( joinColumns[1].unique() );
|
||||
|
||||
// InverseJoinColumns
|
||||
JoinColumn[] inverseJoinColumns = joinTableAnno.inverseJoinColumns();
|
||||
assertEquals( 2, inverseJoinColumns.length );
|
||||
assertEquals( "", inverseJoinColumns[0].name() );
|
||||
assertEquals( "", inverseJoinColumns[0].referencedColumnName() );
|
||||
assertEquals( "", inverseJoinColumns[0].table() );
|
||||
assertEquals( "", inverseJoinColumns[0].columnDefinition() );
|
||||
assertTrue( inverseJoinColumns[0].insertable() );
|
||||
assertTrue( inverseJoinColumns[0].updatable() );
|
||||
assertTrue( inverseJoinColumns[0].nullable() );
|
||||
assertFalse( inverseJoinColumns[0].unique() );
|
||||
assertEquals( "col3", inverseJoinColumns[1].name() );
|
||||
assertEquals( "col4", inverseJoinColumns[1].referencedColumnName() );
|
||||
assertEquals( "table3", inverseJoinColumns[1].table() );
|
||||
assertEquals( "int", inverseJoinColumns[1].columnDefinition() );
|
||||
assertFalse( inverseJoinColumns[1].insertable() );
|
||||
assertFalse( inverseJoinColumns[1].updatable() );
|
||||
assertFalse( inverseJoinColumns[1].nullable() );
|
||||
assertTrue( inverseJoinColumns[1].unique() );
|
||||
|
||||
// UniqueConstraints
|
||||
UniqueConstraint[] uniqueConstraints = joinTableAnno
|
||||
.uniqueConstraints();
|
||||
assertEquals( 2, uniqueConstraints.length );
|
||||
assertEquals( "", uniqueConstraints[0].name() );
|
||||
assertEquals( 1, uniqueConstraints[0].columnNames().length );
|
||||
assertEquals( "col5", uniqueConstraints[0].columnNames()[0] );
|
||||
assertEquals( "uq1", uniqueConstraints[1].name() );
|
||||
assertEquals( 2, uniqueConstraints[1].columnNames().length );
|
||||
assertEquals( "col6", uniqueConstraints[1].columnNames()[0] );
|
||||
assertEquals( "col7", uniqueConstraints[1].columnNames()[1] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeAll() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm8.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
OneToOne relAnno = reader.getAnnotation( OneToOne.class );
|
||||
assertEquals( 1, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCascadeSomeWithDefaultPersist() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm9.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
OneToOne relAnno = reader.getAnnotation( OneToOne.class );
|
||||
assertEquals( 4, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[3] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure that it doesn't break the handler when {@link CascadeType#ALL}
|
||||
* is specified in addition to a default cascade-persist or individual
|
||||
* cascade settings.
|
||||
*/
|
||||
@Test
|
||||
public void testCascadeAllPlusMore() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm10.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
OneToOne relAnno = reader.getAnnotation( OneToOne.class );
|
||||
assertEquals( 6, relAnno.cascade().length );
|
||||
assertEquals( CascadeType.ALL, relAnno.cascade()[0] );
|
||||
assertEquals( CascadeType.PERSIST, relAnno.cascade()[1] );
|
||||
assertEquals( CascadeType.MERGE, relAnno.cascade()[2] );
|
||||
assertEquals( CascadeType.REMOVE, relAnno.cascade()[3] );
|
||||
assertEquals( CascadeType.REFRESH, relAnno.cascade()[4] );
|
||||
assertEquals( CascadeType.DETACH, relAnno.cascade()[5] );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllAttributes() throws Exception {
|
||||
reader = getReader( Entity1.class, "field1", "one-to-one.orm11.xml" );
|
||||
assertAnnotationPresent( OneToOne.class );
|
||||
assertAnnotationPresent( MapsId.class );
|
||||
assertAnnotationPresent( Id.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumn.class );
|
||||
assertAnnotationNotPresent( PrimaryKeyJoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumns.class );
|
||||
assertAnnotationNotPresent( JoinColumn.class );
|
||||
assertAnnotationNotPresent( JoinTable.class );
|
||||
assertAnnotationPresent( Access.class );
|
||||
OneToOne relAnno = reader.getAnnotation( OneToOne.class );
|
||||
assertEquals( 0, relAnno.cascade().length );
|
||||
assertEquals( FetchType.LAZY, relAnno.fetch() );
|
||||
assertEquals( "field2", relAnno.mappedBy() );
|
||||
assertFalse( relAnno.optional() );
|
||||
assertTrue( relAnno.orphanRemoval() );
|
||||
assertEquals( Entity3.class, relAnno.targetEntity() );
|
||||
assertEquals(
|
||||
AccessType.PROPERTY, reader.getAnnotation( Access.class )
|
||||
.value()
|
||||
);
|
||||
assertEquals(
|
||||
"field3", reader.getAnnotation( MapsId.class )
|
||||
.value()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.xml.ejb3;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
import org.hibernate.dialect.CockroachDB192Dialect;
|
||||
import org.hibernate.dialect.PostgreSQL81Dialect;
|
||||
import org.hibernate.dialect.PostgreSQLDialect;
|
||||
import org.hibernate.dialect.TeradataDialect;
|
||||
import org.hibernate.persister.collection.BasicCollectionPersister;
|
||||
|
||||
import org.hibernate.testing.SkipForDialect;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class LegacyEjb3XmlTest extends BaseCoreFunctionalTestCase {
|
||||
@Test
|
||||
@SkipForDialect(value = {PostgreSQL81Dialect.class, PostgreSQLDialect.class, CockroachDB192Dialect.class},
|
||||
comment = "postgresql jdbc driver does not implement the setQueryTimeout method")
|
||||
@SkipForDialect(value = TeradataDialect.class,
|
||||
jiraKey = "HHH-8190",
|
||||
comment = "uses Teradata reserved word - year")
|
||||
public void testEjb3Xml() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
CarModel model = new CarModel();
|
||||
model.setYear( new Date() );
|
||||
Manufacturer manufacturer = new Manufacturer();
|
||||
//s.persist( manufacturer );
|
||||
model.setManufacturer( manufacturer );
|
||||
manufacturer.getModels().add( model );
|
||||
s.persist( model );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
model.setYear( new Date() );
|
||||
manufacturer = (Manufacturer) s.get( Manufacturer.class, manufacturer.getId() );
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Model> cars = s.getNamedQuery( "allModelsPerManufacturer" )
|
||||
.setParameter( "manufacturer", manufacturer )
|
||||
.list();
|
||||
assertEquals( 1, cars.size() );
|
||||
for ( Model car : cars ) {
|
||||
assertNotNull( car.getManufacturer() );
|
||||
s.delete( manufacturer );
|
||||
s.delete( car );
|
||||
}
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXMLEntityHandled() throws Exception {
|
||||
Session s = openSession();
|
||||
s.getTransaction().begin();
|
||||
Lighter l = new Lighter();
|
||||
l.name = "Blue";
|
||||
l.power = "400F";
|
||||
s.persist( l );
|
||||
s.flush();
|
||||
s.getTransaction().rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testXmlDefaultOverriding() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Manufacturer manufacturer = new Manufacturer();
|
||||
s.persist( manufacturer );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
assertEquals( 1, s.getNamedQuery( "manufacturer.findAll" ).list().size() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testMapXMLSupport() throws Exception {
|
||||
Session s = openSession();
|
||||
SessionFactory sf = s.getSessionFactory();
|
||||
Transaction tx = s.beginTransaction();
|
||||
|
||||
// Verify that we can persist an object with a couple Map mappings
|
||||
VicePresident vpSales = new VicePresident();
|
||||
vpSales.name = "Dwight";
|
||||
Company company = new Company();
|
||||
company.conferenceRoomExtensions.put( "8932", "x1234" );
|
||||
company.organization.put( "sales", vpSales );
|
||||
s.persist( company );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
// For the element-collection, check that the orm.xml entries are honored.
|
||||
// This includes: map-key-column/column/collection-table/join-column
|
||||
BasicCollectionPersister confRoomMeta = (BasicCollectionPersister) sf.getCollectionMetadata( Company.class.getName() + ".conferenceRoomExtensions" );
|
||||
assertEquals( "company_id", confRoomMeta.getKeyColumnNames()[0] );
|
||||
assertEquals( "phone_extension", confRoomMeta.getElementColumnNames()[0] );
|
||||
assertEquals( "room_number", confRoomMeta.getIndexColumnNames()[0] );
|
||||
assertEquals( "phone_extension_lookup", confRoomMeta.getTableName() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class[] getAnnotatedClasses() {
|
||||
return new Class[] {
|
||||
CarModel.class,
|
||||
Manufacturer.class,
|
||||
Model.class,
|
||||
Light.class
|
||||
//Lighter.class xml only entuty
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getXmlFiles() {
|
||||
return new String[] {
|
||||
"org/hibernate/test/annotations/xml/ejb3/orm.xml",
|
||||
"org/hibernate/test/annotations/xml/ejb3/orm2.xml",
|
||||
"org/hibernate/test/annotations/xml/ejb3/orm3.xml",
|
||||
"org/hibernate/test/annotations/xml/ejb3/orm4.xml"
|
||||
};
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.xml.ejb3;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.AnnotatedElement;
|
||||
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
import org.hibernate.cfg.annotations.reflection.XMLContext;
|
||||
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.io.SAXReader;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test superclass to provide utility methods for testing the mapping of JPA
|
||||
* XML to JPA annotations. The configuration is built within each test, and no
|
||||
* database is used. Thus, no schema generation or cleanup will be performed.
|
||||
* <p>
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.Ejb3XmlTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@Deprecated
|
||||
abstract class LegacyEjb3XmlTestCase extends BaseUnitTestCase {
|
||||
protected JPAOverriddenAnnotationReader reader;
|
||||
|
||||
protected void assertAnnotationPresent(Class<? extends Annotation> annotationType) {
|
||||
assertTrue(
|
||||
"Expected annotation " + annotationType.getSimpleName() + " was not present",
|
||||
reader.isAnnotationPresent( annotationType )
|
||||
);
|
||||
}
|
||||
|
||||
protected void assertAnnotationNotPresent(Class<? extends Annotation> annotationType) {
|
||||
assertFalse(
|
||||
"Unexpected annotation " + annotationType.getSimpleName() + " was present",
|
||||
reader.isAnnotationPresent( annotationType )
|
||||
);
|
||||
}
|
||||
|
||||
protected JPAOverriddenAnnotationReader getReader(Class<?> entityClass, String fieldName, String ormResourceName)
|
||||
throws Exception {
|
||||
AnnotatedElement el = getAnnotatedElement( entityClass, fieldName );
|
||||
XMLContext xmlContext = getContext( ormResourceName );
|
||||
return new JPAOverriddenAnnotationReader( el, xmlContext, BootstrapContextImpl.INSTANCE );
|
||||
}
|
||||
|
||||
protected AnnotatedElement getAnnotatedElement(Class<?> entityClass, String fieldName) throws Exception {
|
||||
return entityClass.getDeclaredField( fieldName );
|
||||
}
|
||||
|
||||
protected XMLContext getContext(String resourceName) throws Exception {
|
||||
InputStream is = getClass().getResourceAsStream( resourceName );
|
||||
assertNotNull( "Could not load resource " + resourceName, is );
|
||||
return getContext( is );
|
||||
}
|
||||
|
||||
protected XMLContext getContext(InputStream is) throws Exception {
|
||||
XMLContext xmlContext = new XMLContext( BootstrapContextImpl.INSTANCE );
|
||||
SAXReader reader = new SAXReader();
|
||||
reader.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", false );
|
||||
reader.setFeature( "http://xml.org/sax/features/external-general-entities", false );
|
||||
reader.setFeature( "http://xml.org/sax/features/external-parameter-entities", false );
|
||||
Document doc = reader.read( is );
|
||||
xmlContext.addDocument( doc );
|
||||
return xmlContext;
|
||||
}
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.xml.ejb3;
|
||||
|
||||
import org.hibernate.InvalidMappingException;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
import org.hibernate.internal.util.xml.UnsupportedOrmXsdVersionException;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseUnitTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.NonExistentOrmVersionTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-6271")
|
||||
public class LegacyNonExistentOrmVersionTest extends BaseUnitTestCase {
|
||||
@Test
|
||||
public void testNonExistentOrmVersion() {
|
||||
try {
|
||||
new MetadataSources()
|
||||
.addResource( "org/hibernate/test/annotations/xml/ejb3/orm5.xml" )
|
||||
.buildMetadata();
|
||||
fail( "Expecting failure due to unsupported xsd version" );
|
||||
}
|
||||
catch ( InvalidMappingException expected ) {
|
||||
}
|
||||
catch ( UnsupportedOrmXsdVersionException expected ) {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.xml.ejb3;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
import org.hibernate.internal.CoreMessageLogger;
|
||||
import org.hibernate.internal.util.xml.ErrorLogger;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.testing.logger.LoggerInspectionRule;
|
||||
import org.hibernate.testing.logger.Triggerable;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.OrmVersion1SupportedTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-6271")
|
||||
public class LegacyOrmVersion1SupportedTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Rule
|
||||
public LoggerInspectionRule logInspection = new LoggerInspectionRule(
|
||||
Logger.getMessageLogger(
|
||||
CoreMessageLogger.class,
|
||||
ErrorLogger.class.getName()
|
||||
)
|
||||
);
|
||||
|
||||
@Test
|
||||
public void testOrm1Support() {
|
||||
Triggerable triggerable = logInspection.watchForLogMessages( "HHH00196" );
|
||||
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Light light = new Light();
|
||||
light.name = "the light at the end of the tunnel";
|
||||
s.persist( light );
|
||||
s.flush();
|
||||
s.clear();
|
||||
|
||||
assertEquals( 1, s.getNamedQuery( "find.the.light" ).list().size() );
|
||||
tx.rollback();
|
||||
s.close();
|
||||
|
||||
assertFalse( triggerable.wasTriggered() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] getXmlFiles() {
|
||||
return new String[] { "org/hibernate/test/annotations/xml/ejb3/orm2.xml" };
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* 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.annotations.xml.ejb3;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||
import org.hibernate.test.annotations.xml.ejb3.PreParsedOrmXmlTest.NonAnnotatedEntity;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Equivalent to {@link org.hibernate.test.annotations.xml.ejb3.PreParsedOrmXmlTest}
|
||||
* for the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*
|
||||
* @author Emmanuel Bernard
|
||||
* @deprecated This test will be removed in Hibernate ORM 6, along with the legacy {@link JPAOverriddenAnnotationReader}.
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-14530")
|
||||
public class LegacyPreParsedOrmXmlTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Override
|
||||
protected void addMappings(Configuration configuration) {
|
||||
super.addMappings( configuration );
|
||||
try (InputStream xmlStream = Thread.currentThread().getContextClassLoader()
|
||||
.getResourceAsStream( "org/hibernate/test/annotations/xml/ejb3/pre-parsed-orm.xml" )) {
|
||||
Binding<?> parsed = configuration.getXmlMappingBinderAccess().bind( xmlStream );
|
||||
configuration.addXmlMapping( parsed );
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new UncheckedIOException( e );
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreParsedOrmXml() {
|
||||
// Just check that the entity can be persisted, which means the mapping file was taken into account
|
||||
NonAnnotatedEntity persistedEntity = new NonAnnotatedEntity( "someName" );
|
||||
inTransaction( s -> s.persist( persistedEntity ) );
|
||||
inTransaction( s -> {
|
||||
NonAnnotatedEntity retrievedEntity = s.find( NonAnnotatedEntity.class, persistedEntity.getId() );
|
||||
assertThat( retrievedEntity ).extracting( NonAnnotatedEntity::getName )
|
||||
.isEqualTo( persistedEntity.getName() );
|
||||
} );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue