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();
}
}
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();
}
}
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();
}
}
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;
}
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");
}
}
Aggregations