Search in sources :

Example 1 with JPAOverriddenAnnotationReader

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

the class JPAOverriddenAnnotationReaderTest method testMappedSuperclassAnnotations.

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

Example 2 with JPAOverriddenAnnotationReader

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

the class JPAOverriddenAnnotationReaderTest method testElementCollectionConverter.

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

Example 3 with JPAOverriddenAnnotationReader

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

the class JPAOverriddenAnnotationReaderTest method testVersionRelatedAnnotations.

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

Example 4 with JPAOverriddenAnnotationReader

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

the class JPAOverriddenAnnotationReaderTest method testEntityListeners.

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

Example 5 with JPAOverriddenAnnotationReader

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

the class JPAOverriddenAnnotationReaderTest method testBasicRelatedAnnotations.

@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));
}
Also used : Field(java.lang.reflect.Field) 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