Search in sources :

Example 91 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class AccessMappingTest method testPropertyAnnotationPlacement.

@Test
public void testPropertyAnnotationPlacement() throws Exception {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = Course7.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Student.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        EntityTuplizer tuplizer = factory.getEntityPersister(classUnderTest.getName()).getEntityMetamodel().getTuplizer();
        assertTrue("Property access should be used.", tuplizer.getIdentifierGetter() instanceof GetterMethodImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) GetterMethodImpl(org.hibernate.property.access.spi.GetterMethodImpl) Test(org.junit.Test)

Example 92 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class AccessMappingTest method testDefaultFieldAccessIsInherited.

@Test
public void testDefaultFieldAccessIsInherited() throws Exception {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = User.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Person.class);
    cfg.addAnnotatedClass(Being.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        EntityTuplizer tuplizer = factory.getEntityPersister(classUnderTest.getName()).getEntityMetamodel().getTuplizer();
        assertTrue("Field access should be used since the default access mode gets inherited", tuplizer.getIdentifierGetter() instanceof GetterFieldImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) GetterFieldImpl(org.hibernate.property.access.spi.GetterFieldImpl) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Test(org.junit.Test)

Example 93 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class AccessMappingTest method testExplicitPropertyAccessAnnotationsWithJpaStyleOverride.

@Test
public void testExplicitPropertyAccessAnnotationsWithJpaStyleOverride() throws Exception {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = Course5.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Student.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        EntityTuplizer tuplizer = factory.getEntityPersister(classUnderTest.getName()).getEntityMetamodel().getTuplizer();
        assertTrue("Field access should be used.", tuplizer.getIdentifierGetter() instanceof GetterFieldImpl);
        assertTrue("Property access should be used.", tuplizer.getGetter(0) instanceof GetterMethodImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) 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) Test(org.junit.Test)

Example 94 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class XmlAccessTest method testAccessOnEntityXmlElement.

@Test
public void testAccessOnEntityXmlElement() throws Exception {
    Class<?> classUnderTest = Tourist.class;
    List<Class<?>> classes = new ArrayList<Class<?>>();
    classes.add(classUnderTest);
    List<String> configFiles = Collections.emptyList();
    SessionFactoryImplementor factory = buildSessionFactory(classes, configFiles);
    // without any xml configuration we have field access
    assertAccessType(factory, classUnderTest, AccessType.FIELD);
    factory.close();
    // now with an additional xml configuration file changing the default access type for Tourist using entity level config
    configFiles = new ArrayList<String>();
    configFiles.add("org/hibernate/test/annotations/access/xml/Tourist4.xml");
    factory = buildSessionFactory(classes, configFiles);
    assertAccessType(factory, classUnderTest, AccessType.PROPERTY);
    factory.close();
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 95 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class XmlAccessTest method testAccessOnElementCollectionXmlElement.

@Test
public void testAccessOnElementCollectionXmlElement() throws Exception {
    Class<?> classUnderTest = Boy.class;
    List<Class<?>> classes = new ArrayList<Class<?>>();
    classes.add(classUnderTest);
    List<String> configFiles = new ArrayList<String>();
    configFiles.add("org/hibernate/test/annotations/access/xml/Boy.xml");
    SessionFactoryImplementor factory = buildSessionFactory(classes, configFiles);
    assertAccessType(factory, classUnderTest, AccessType.PROPERTY);
    factory.close();
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)129 Test (org.junit.Test)46 Configuration (org.hibernate.cfg.Configuration)27 SQLException (java.sql.SQLException)18 Type (org.hibernate.type.Type)16 EntityPersister (org.hibernate.persister.entity.EntityPersister)13 Connection (java.sql.Connection)12 HibernateException (org.hibernate.HibernateException)12 PreparedStatement (java.sql.PreparedStatement)11 Metadata (org.hibernate.boot.Metadata)11 Statement (java.sql.Statement)10 ArrayList (java.util.ArrayList)10 JdbcConnectionAccess (org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess)10 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)10 Serializable (java.io.Serializable)9 EncapsulatedCompositeIdResultSetProcessorTest (org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)8 HashMap (java.util.HashMap)7 Integrator (org.hibernate.integrator.spi.Integrator)7 SessionFactoryServiceRegistry (org.hibernate.service.spi.SessionFactoryServiceRegistry)7 Map (java.util.Map)6