Search in sources :

Example 31 with Configuration

use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.

the class LoadPlanStructureAssertionTest method testAnotherBasicCollection.

@Test
public void testAnotherBasicCollection() {
    Configuration cfg = new Configuration();
    cfg.addAnnotatedClass(Boy.class);
    cfg.addAnnotatedClass(Country.class);
    cfg.addAnnotatedClass(TestCourse.class);
    cfg.addAnnotatedClass(Matrix.class);
    SessionFactoryImplementor sf = (SessionFactoryImplementor) cfg.buildSessionFactory();
    try {
        doCompare(sf, (OuterJoinLoadable) sf.getClassMetadata(Boy.class));
    } finally {
        sf.close();
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Test(org.junit.Test) EncapsulatedCompositeIdResultSetProcessorTest(org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)

Example 32 with Configuration

use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.

the class LoadPlanStructureAssertionTest method testSpecialOneToOne.

@Test
public void testSpecialOneToOne() {
    // tests the mappings defined in org.hibernate.test.onetoone.joined.JoinedSubclassOneToOneTest
    Configuration cfg = new Configuration();
    cfg.addResource("org/hibernate/test/onetoone/formula/Person.hbm.xml");
    SessionFactoryImplementor sf = (SessionFactoryImplementor) cfg.buildSessionFactory();
    try {
        doCompare(sf, (OuterJoinLoadable) sf.getClassMetadata(org.hibernate.test.onetoone.formula.Person.class));
    } finally {
        sf.close();
    }
}
Also used : Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Test(org.junit.Test) EncapsulatedCompositeIdResultSetProcessorTest(org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)

Example 33 with Configuration

use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.

the class CompositesWalkingTest method testEntityComposite.

/**
	 * Test one-level composites defined as part of an entity.
	 */
@Test
public void testEntityComposite() {
    final SessionFactory sf = new Configuration().addAnnotatedClass(TestCourse.class).buildSessionFactory();
    try {
        final EntityPersister ep = (EntityPersister) sf.getClassMetadata(TestCourse.class);
        MetamodelGraphWalker.visitEntity(new LoggingAssociationVisitationStrategy(), ep);
    } finally {
        sf.close();
    }
}
Also used : SessionFactory(org.hibernate.SessionFactory) EntityPersister(org.hibernate.persister.entity.EntityPersister) Configuration(org.hibernate.cfg.Configuration) TestCourse(org.hibernate.test.annotations.collectionelement.TestCourse) Test(org.junit.Test)

Example 34 with Configuration

use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.

the class TenantResolverConfigurationTest method constructAndConfigureConfiguration.

@Override
protected Configuration constructAndConfigureConfiguration() {
    Configuration configuration = super.constructAndConfigureConfiguration();
    configuration.setCurrentTenantIdentifierResolver(currentTenantResolver);
    return configuration;
}
Also used : Configuration(org.hibernate.cfg.Configuration)

Example 35 with Configuration

use of org.hibernate.cfg.Configuration in project hibernate-orm by hibernate.

the class MappingExceptionTest method testNotFound.

@Test
public void testNotFound() throws MappingException, MalformedURLException {
    Configuration cfg = new Configuration();
    try {
        cfg.addCacheableFile("completelybogus.hbm.xml");
        fail();
    } catch (MappingNotFoundException e) {
        assertEquals(e.getType(), "file");
        assertEquals(e.getPath(), "completelybogus.hbm.xml");
    } catch (org.hibernate.boot.MappingNotFoundException e) {
        assertEquals(e.getOrigin().getType(), SourceType.FILE);
        assertEquals(e.getOrigin().getName(), "completelybogus.hbm.xml");
    }
    try {
        cfg.addCacheableFile(new File("completelybogus.hbm.xml"));
        fail();
    } catch (MappingNotFoundException e) {
        assertEquals(e.getType(), "file");
        assertEquals(e.getPath(), "completelybogus.hbm.xml");
    } catch (org.hibernate.boot.MappingNotFoundException e) {
        assertEquals(e.getOrigin().getType(), SourceType.FILE);
        assertEquals(e.getOrigin().getName(), "completelybogus.hbm.xml");
    }
    try {
        // TODO: String.class result in npe, because no classloader exists for it
        cfg.addClass(Hibernate.class);
        fail();
    } catch (MappingNotFoundException inv) {
        assertEquals(inv.getType(), "resource");
        assertEquals(inv.getPath(), "org/hibernate/Hibernate.hbm.xml");
    } catch (org.hibernate.boot.MappingNotFoundException e) {
        assertEquals(e.getOrigin().getType(), SourceType.RESOURCE);
        assertEquals(e.getOrigin().getName(), "org/hibernate/Hibernate.hbm.xml");
    }
    try {
        cfg.addFile("completelybogus.hbm.xml");
        fail();
    } catch (MappingNotFoundException e) {
        assertEquals(e.getType(), "file");
        assertEquals(e.getPath(), "completelybogus.hbm.xml");
    } catch (org.hibernate.boot.MappingNotFoundException e) {
        assertEquals(e.getOrigin().getType(), SourceType.FILE);
        assertEquals(e.getOrigin().getName(), "completelybogus.hbm.xml");
    }
    try {
        cfg.addFile(new File("completelybogus.hbm.xml"));
        fail();
    } catch (MappingNotFoundException inv) {
        assertEquals(inv.getType(), "file");
        assertEquals(inv.getPath(), "completelybogus.hbm.xml");
    } catch (org.hibernate.boot.MappingNotFoundException e) {
        assertEquals(e.getOrigin().getType(), SourceType.FILE);
        assertEquals(e.getOrigin().getName(), "completelybogus.hbm.xml");
    }
    try {
        cfg.addInputStream(new ByteArrayInputStream(new byte[0]));
        fail();
    } catch (org.hibernate.boot.InvalidMappingException e) {
        assertEquals(SourceType.INPUT_STREAM, e.getOrigin().getType());
        assertEquals(null, e.getOrigin().getName());
    } catch (InvalidMappingException inv) {
        assertEquals(inv.getType(), "input stream");
        assertEquals(inv.getPath(), null);
    }
    try {
        cfg.addResource("nothere");
        fail();
    } catch (MappingNotFoundException inv) {
        assertEquals(inv.getType(), "resource");
        assertEquals(inv.getPath(), "nothere");
    } catch (org.hibernate.boot.MappingNotFoundException e) {
        assertEquals(e.getOrigin().getType(), SourceType.RESOURCE);
        assertEquals(e.getOrigin().getName(), "nothere");
    }
    try {
        cfg.addResource("nothere", getClass().getClassLoader());
        fail();
    } catch (MappingNotFoundException inv) {
        assertEquals(inv.getType(), "resource");
        assertEquals(inv.getPath(), "nothere");
    } catch (org.hibernate.boot.MappingNotFoundException e) {
        assertEquals(e.getOrigin().getType(), SourceType.RESOURCE);
        assertEquals(e.getOrigin().getName(), "nothere");
    }
    try {
        cfg.addURL(new URL("file://nothere"));
        fail();
    } catch (org.hibernate.boot.MappingNotFoundException e) {
        assertEquals(e.getOrigin().getType(), SourceType.URL);
        assertEquals(e.getOrigin().getName(), "file://nothere");
    } catch (InvalidMappingException inv) {
        assertEquals(inv.getType(), "URL");
        assertEquals(inv.getPath(), "file://nothere");
    } catch (org.hibernate.boot.MappingException me) {
        assertEquals(me.getOrigin().getType(), SourceType.URL);
        assertEquals(me.getOrigin().getName(), "file://nothere");
    }
}
Also used : MappingNotFoundException(org.hibernate.MappingNotFoundException) Configuration(org.hibernate.cfg.Configuration) ByteArrayInputStream(java.io.ByteArrayInputStream) InvalidMappingException(org.hibernate.InvalidMappingException) File(java.io.File) URL(java.net.URL) Test(org.junit.Test)

Aggregations

Configuration (org.hibernate.cfg.Configuration)190 Test (org.junit.Test)66 Session (org.hibernate.Session)37 SessionFactory (org.hibernate.SessionFactory)35 SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)27 Before (org.junit.Before)20 BeforeClass (org.junit.BeforeClass)20 File (java.io.File)18 ServiceRegistry (org.hibernate.service.ServiceRegistry)14 Properties (java.util.Properties)13 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)9 HibernateException (org.hibernate.HibernateException)8 EncapsulatedCompositeIdResultSetProcessorTest (org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)8 MappingException (org.hibernate.MappingException)7 Transaction (org.hibernate.Transaction)7 URL (java.net.URL)6 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)6 TestForIssue (org.hibernate.testing.TestForIssue)6 EntityTuplizer (org.hibernate.tuple.entity.EntityTuplizer)6 BigDecimal (java.math.BigDecimal)5