Search in sources :

Example 11 with JPAOverriddenAnnotationReader

use of org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReaderTest method testEntityRelatedAnnotationsMetadataComplete.

@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));
}
Also used : XMLContext(org.hibernate.cfg.annotations.reflection.XMLContext) JPAOverriddenAnnotationReader(org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader) Test(org.junit.Test)

Aggregations

JPAOverriddenAnnotationReader (org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader)11 XMLContext (org.hibernate.cfg.annotations.reflection.XMLContext)11 Test (org.junit.Test)10 Field (java.lang.reflect.Field)6 Method (java.lang.reflect.Method)3 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Columns (org.hibernate.annotations.Columns)1 TestForIssue (org.hibernate.testing.TestForIssue)1