本文整理了Java中org.hibernate.cfg.Configuration.configure()
方法的一些代码示例,展示了Configuration.configure()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.configure()
方法的具体详情如下:
包路径:org.hibernate.cfg.Configuration
类名称:Configuration
方法名:configure
[英]Use the mappings and properties specified in an application resource named hibernate.cfg.xml.
[中]使用名为hibernate的应用程序资源中指定的映射和属性。cfg。xml。
代码示例来源:origin: hibernate/hibernate-orm
/**
* Use the mappings and properties specified in an application resource named <tt>hibernate.cfg.xml</tt>.
*
* @return this for method chaining
*
* @throws HibernateException Generally indicates we cannot find <tt>hibernate.cfg.xml</tt>
*
* @see #configure(String)
*/
public Configuration configure() throws HibernateException {
return configure( StandardServiceRegistryBuilder.DEFAULT_CFG_RESOURCE_NAME );
}
代码示例来源:origin: hibernate/hibernate-orm
@TransactionAttribute(TransactionAttributeType.NEVER)
public void start() {
try {
Configuration configuration = new Configuration();
configuration = configuration.configure( "hibernate.cfg.xml" );
configuration.addAnnotatedClass( WildFlyDdlEntity.class );
sessionFactory = configuration.buildSessionFactory();
}
catch (Throwable ex) {
System.err.println( "Initial SessionFactory creation failed." + ex );
throw new ExceptionInInitializerError( ex );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testDeclarativeMix() throws Exception {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
SessionFactory sf = cfg.buildSessionFactory();
assertNotNull( sf );
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
Query q = s.createQuery( "from Boat" );
assertEquals( 0, q.list().size() );
q = s.createQuery( "from Plane" );
assertEquals( 0, q.list().size() );
tx.commit();
s.close();
sf.close();
}
@Test
代码示例来源:origin: hibernate/hibernate-orm
public void start() {
Configuration configuration = new Configuration();
configuration = configuration.configure( "hibernate.cfg.xml" );
configuration.addAnnotatedClass( WildFlyDdlEntity.class );
// creating the SF should run schema creation
sessionFactory = configuration.buildSessionFactory();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testHbmWithSubclassExtends() throws Exception {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.addClass( Ferry.class );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
SessionFactory sf = cfg.buildSessionFactory();
assertNotNull( sf );
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
Query q = s.createQuery( "from Ferry" );
assertEquals( 0, q.list().size() );
q = s.createQuery( "from Plane" );
assertEquals( 0, q.list().size() );
tx.commit();
s.close();
sf.close();
}
@Test
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testAnnReferencesHbm() throws Exception {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.addAnnotatedClass( Port.class );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
SessionFactory sf = cfg.buildSessionFactory();
assertNotNull( sf );
Session s = sf.openSession();
Transaction tx = s.beginTransaction();
Query q = s.createQuery( "from Boat" );
assertEquals( 0, q.list().size() );
q = s.createQuery( "from Port" );
assertEquals( 0, q.list().size() );
tx.commit();
s.close();
sf.close();
}
}
代码示例来源:origin: hibernate/hibernate-orm
@BeforeClassOnce
public void init() throws URISyntaxException {
config = new Configuration();
URL url = Thread.currentThread().getContextClassLoader().getResource( getHibernateConfigurationFileName() );
config.configure( new File( url.toURI() ) );
String auditStrategy = getAuditStrategy();
if ( auditStrategy != null && !"".equals( auditStrategy ) ) {
config.setProperty( EnversSettings.AUDIT_STRATEGY, auditStrategy );
}
config.setProperty( Environment.USE_NEW_ID_GENERATOR_MAPPINGS, "true" );
config.setProperty( EnversSettings.USE_REVISION_ENTITY_WITH_NATIVE_ID, "false" );
addProperties( config );
this.initMappings();
serviceRegistry = ServiceRegistryBuilder.buildServiceRegistry( config.getProperties() );
sessionFactory = config.buildSessionFactory( serviceRegistry );
}
代码示例来源:origin: org.hibernate/hibernate-annotations
@Override
public AnnotationConfiguration configure(String resource) throws HibernateException {
super.configure( resource );
return this;
}
代码示例来源:origin: org.hibernate/hibernate-annotations
@Override
public AnnotationConfiguration configure(URL url) throws HibernateException {
super.configure( url );
return this;
}
代码示例来源:origin: org.hibernate/hibernate-annotations
@Override
public AnnotationConfiguration configure(File configFile) throws HibernateException {
super.configure( configFile );
return this;
}
代码示例来源:origin: org.hibernate/hibernate-annotations
@Override
public AnnotationConfiguration configure(org.w3c.dom.Document document) throws HibernateException {
super.configure( document );
return this;
}
代码示例来源:origin: org.hibernate/hibernate-annotations
@Override
public AnnotationConfiguration configure() throws HibernateException {
super.configure();
return this;
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testPrecedenceHbm() throws Exception {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.addAnnotatedClass( Boat.class );
SessionFactory sf = cfg.buildSessionFactory();
assertNotNull( sf );
Session s = sf.openSession();
s.getTransaction().begin();
Boat boat = new Boat();
boat.setSize( 12 );
boat.setWeight( 34 );
s.persist( boat );
s.getTransaction().commit();
s.clear();
Transaction tx = s.beginTransaction();
boat = (Boat) s.get( Boat.class, boat.getId() );
assertTrue( "Annotation has precedence", 34 != boat.getWeight() );
s.delete( boat );
//s.getTransaction().commit();
tx.commit();
s.close();
sf.close();
}
@Test
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testPrecedenceAnnotation() throws Exception {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.setProperty( Configuration.ARTEFACT_PROCESSING_ORDER, "class, hbm" );
cfg.addAnnotatedClass( Boat.class );
SessionFactory sf = cfg.buildSessionFactory();
assertNotNull( sf );
Session s = sf.openSession();
s.getTransaction().begin();
Boat boat = new Boat();
boat.setSize( 12 );
boat.setWeight( 34 );
s.persist( boat );
s.getTransaction().commit();
s.clear();
Transaction tx = s.beginTransaction();
boat = (Boat) s.get( Boat.class, boat.getId() );
assertTrue( "Annotation has precedence", 34 == boat.getWeight() );
s.delete( boat );
tx.commit();
s.close();
sf.close();
}
@Test
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testIgnoringHbm() throws Exception {
Configuration cfg = new Configuration();
cfg.configure( "org/hibernate/test/annotations/hibernate.cfg.xml" );
cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
cfg.setProperty( Configuration.ARTEFACT_PROCESSING_ORDER, "class" );
代码示例来源:origin: Impetus/Kundera
conf.configure(propertyFileName);
break;
代码示例来源:origin: openmrs/openmrs-core
public SessionFactory buildSessionFactory() {
Configuration config = new Configuration().configure();
//H2 version we use behaves differently from H2Dialect in Hibernate so we provide our implementation
config.setProperty(Environment.DIALECT, H2LessStrictDialect.class.getName());
config.setProperty(Environment.URL, connectionUrl);
config.setProperty(Environment.DRIVER, "org.h2.Driver");
config.setProperty(Environment.USER, "sa");
config.setProperty(Environment.PASS, "sa");
config.setProperty(Environment.USE_SECOND_LEVEL_CACHE, "false");
config.setProperty(Environment.USE_QUERY_CACHE, "false");
//Let's validate HBMs against the actual schema
config.setProperty(Environment.HBM2DDL_AUTO, "validate");
return config.buildSessionFactory();
}
}
代码示例来源:origin: magro/memcached-session-manager
@BeforeTest
protected void beforeTest() {
Configuration configuration = new Configuration()
.addAnnotatedClass(Person.class)
.addAnnotatedClass(Animal.class)
.configure();
StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings( configuration.getProperties() )
.build();
_sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}
代码示例来源:origin: yahoo/elide
@Override
public Set<Object> getSingletons() {
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Elide elide = new Elide(new ElideSettingsBuilder(new AbstractHibernateStore.Builder(sessionFactory).build())
.withAuditLogger(new Slf4jLogger())
.build());
Set<Object> set = new HashSet<>();
set.add(new JsonApiEndpoint(elide, v -> null));
return set;
}
}
代码示例来源:origin: yahoo/elide
@Override
protected void configure() {
DefaultOpaqueUserFunction noUserFn = v -> null;
bind(noUserFn).to(DefaultOpaqueUserFunction.class).named("elideUserExtractionFunction");
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Elide elide = new Elide(new ElideSettingsBuilder(new HibernateStore.Builder(sessionFactory).build())
.withAuditLogger(new Slf4jLogger())
.build());
bind(elide).to(Elide.class).named("elide");
}
});
内容来源于网络,如有侵权,请联系作者删除!