Search in sources :

Example 6 with BasicEntityIdentifierMappingImpl

use of org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl in project hibernate-orm by hibernate.

the class AccessMappingTest method testDefaultPropertyAccessIsInherited.

@Test
public void testDefaultPropertyAccessIsInherited() {
    Configuration cfg = new Configuration();
    cfg.addAnnotatedClass(Horse.class);
    cfg.addAnnotatedClass(Animal.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        EntityPersister entityPersister = factory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(Animal.class.getName());
        final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping();
        assertTrue("Property access should be used since explicity configured via @Access", identifierMapping.getPropertyAccess().getGetter() instanceof GetterMethodImpl);
        entityPersister = factory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(Horse.class.getName());
        assertTrue("Field access should be used since the default access mode gets inherited", entityPersister.getAttributeMapping(0).getPropertyAccess().getGetter() instanceof GetterFieldImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) GetterFieldImpl(org.hibernate.property.access.spi.GetterFieldImpl) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) GetterMethodImpl(org.hibernate.property.access.spi.GetterMethodImpl) BasicEntityIdentifierMappingImpl(org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl) Test(org.junit.Test)

Example 7 with BasicEntityIdentifierMappingImpl

use of org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl in project hibernate-orm by hibernate.

the class AccessMappingTest method testFieldAnnotationPlacement.

@Test
public void testFieldAnnotationPlacement() {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = Course6.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Student.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        final EntityPersister entityPersister = factory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(classUnderTest.getName());
        final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping();
        assertTrue("Field access should be used.", identifierMapping.getPropertyAccess().getGetter() instanceof GetterFieldImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) GetterFieldImpl(org.hibernate.property.access.spi.GetterFieldImpl) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) BasicEntityIdentifierMappingImpl(org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl) Test(org.junit.Test)

Example 8 with BasicEntityIdentifierMappingImpl

use of org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl in project hibernate-orm by hibernate.

the class AccessMappingTest method testPropertyAnnotationPlacement.

@Test
public void testPropertyAnnotationPlacement() {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = Course7.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Student.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        final EntityPersister entityPersister = factory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(classUnderTest.getName());
        final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping();
        assertTrue("Property access should be used.", identifierMapping.getPropertyAccess().getGetter() instanceof GetterMethodImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) GetterMethodImpl(org.hibernate.property.access.spi.GetterMethodImpl) BasicEntityIdentifierMappingImpl(org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl) Test(org.junit.Test)

Example 9 with BasicEntityIdentifierMappingImpl

use of org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl in project hibernate-orm by hibernate.

the class AccessMappingTest method testExplicitPropertyAccessAnnotationsWithHibernateStyleOverride.

@Test
public void testExplicitPropertyAccessAnnotationsWithHibernateStyleOverride() {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = Course3.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Student.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        final EntityPersister entityPersister = factory.getRuntimeMetamodels().getMappingMetamodel().getEntityDescriptor(classUnderTest.getName());
        final BasicEntityIdentifierMappingImpl identifierMapping = (BasicEntityIdentifierMappingImpl) entityPersister.getIdentifierMapping();
        assertTrue("Field access should be used.", identifierMapping.getPropertyAccess().getGetter() instanceof GetterFieldImpl);
        assertTrue("Property access should be used.", entityPersister.getAttributeMapping(0).getPropertyAccess().getGetter() instanceof GetterMethodImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) GetterFieldImpl(org.hibernate.property.access.spi.GetterFieldImpl) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) GetterMethodImpl(org.hibernate.property.access.spi.GetterMethodImpl) BasicEntityIdentifierMappingImpl(org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl) Test(org.junit.Test)

Aggregations

BasicEntityIdentifierMappingImpl (org.hibernate.metamodel.mapping.internal.BasicEntityIdentifierMappingImpl)9 Configuration (org.hibernate.cfg.Configuration)7 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)7 EntityPersister (org.hibernate.persister.entity.EntityPersister)7 Test (org.junit.Test)7 GetterFieldImpl (org.hibernate.property.access.spi.GetterFieldImpl)5 GetterMethodImpl (org.hibernate.property.access.spi.GetterMethodImpl)5 Column (org.hibernate.mapping.Column)2 EntityMappingType (org.hibernate.metamodel.mapping.EntityMappingType)2 BasicType (org.hibernate.type.BasicType)2 CompositeType (org.hibernate.type.CompositeType)2 Type (org.hibernate.type.Type)2 ManagedMappingType (org.hibernate.metamodel.mapping.ManagedMappingType)1 InFlightEntityMappingType (org.hibernate.metamodel.mapping.internal.InFlightEntityMappingType)1 SqlAstJoinType (org.hibernate.sql.ast.SqlAstJoinType)1 AnyType (org.hibernate.type.AnyType)1 AssociationType (org.hibernate.type.AssociationType)1 CollectionType (org.hibernate.type.CollectionType)1 EntityType (org.hibernate.type.EntityType)1 JavaType (org.hibernate.type.descriptor.java.JavaType)1