本文整理汇总了Java中org.hibernate.boot.registry.StandardServiceRegistry类的典型用法代码示例。如果您正苦于以下问题:Java StandardServiceRegistry类的具体用法?Java StandardServiceRegistry怎么用?Java StandardServiceRegistry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StandardServiceRegistry类属于org.hibernate.boot.registry包,在下文中一共展示了StandardServiceRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
public static SessionFactory getSessionFactory() {
if (sessionFactory == null) {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // configures settings from hibernate.cfg.xml
.build();
try {
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
} catch (Exception e) {
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy(registry);
throw new RuntimeException(e);
}
}
return sessionFactory;
}
示例2: setUp
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
@BeforeClass
protected void setUp() throws Exception {
// A SessionFactory is set up once for an application!
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // configures settings from hibernate.cfg.xml
.build();
try {
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
}
catch (Exception e) {
e.printStackTrace();
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy( registry );
}
}
示例3: init
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
private static void init() {
// 从hibernate.cfg.xml文件初始化
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // configures settings from hibernate.cfg.xml
.build();
try {
// build 一个sessionFactory
sessionFactory = new MetadataSources(registry)
.buildMetadata()
.buildSessionFactory();
} catch (Exception e) {
e.printStackTrace();
// 错误则打印输出,并销毁
StandardServiceRegistryBuilder.destroy(registry);
}
}
示例4: getStandardServiceRegistry
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
private static StandardServiceRegistry getStandardServiceRegistry(ServiceRegistry serviceRegistry) {
if ( serviceRegistry == null ) {
throw new HibernateException( "ServiceRegistry passed to MetadataBuilder cannot be null" );
}
if ( StandardServiceRegistry.class.isInstance( serviceRegistry ) ) {
return ( StandardServiceRegistry ) serviceRegistry;
}
else if ( BootstrapServiceRegistry.class.isInstance( serviceRegistry ) ) {
log.debugf(
"ServiceRegistry passed to MetadataBuilder was a BootstrapServiceRegistry; this likely wont end well" +
"if attempt is made to build SessionFactory"
);
return new StandardServiceRegistryBuilder( (BootstrapServiceRegistry) serviceRegistry ).build();
}
else {
throw new HibernateException(
String.format(
"Unexpected type of ServiceRegistry [%s] encountered in attempt to build MetadataBuilder",
serviceRegistry.getClass().getName()
)
);
}
}
示例5: HibernateUserDao
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
public HibernateUserDao() {
// hibernate5
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure() // configures
.build();
try {
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
} catch (Exception e) {
// The registry would be destroyed by the SessionFactory, but we had
// trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy(registry);
}
// hibernate4
// try {
// // Create the SessionFactory from hibernate.cfg.xml
// sessionFactory = new
// Configuration().configure().buildSessionFactory();
// } catch (Throwable ex) {
// // Make sure you log the exception, as it might be swallowed
// System.err.println("Initial SessionFactory creation failed." + ex);
// throw new ExceptionInInitializerError(ex);
// }
}
示例6: setUp
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
@BeforeClass
protected void setUp() throws Exception {
// A SessionFactory is set up once for an application!
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // configures settings from hibernate.cfg.xml
.build();
try {
sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
}
catch (Exception e) {
e.printStackTrace();
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy( registry );
}
}
示例7: start
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
@Override
public void start() {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.applySetting("hibernate.connection.username", config.persistence.user)
.applySetting("hibernate.connection.password", config.persistence.pass)
.applySetting("hibernate.connection.driver_class", config.persistence.driver)
.applySetting("hibernate.connection.url", config.persistence.url)
.applySetting("hibernate.dialect", config.persistence.dialect)
.applySetting("hibernate.connection.pool_size", config.persistence.pool_size + "")
.applySetting("hibernate.hbm2ddl.auto", "update")
.applySetting("hibernate.show_sql", config.persistence.showSQL + "")
.build();
MetadataSources sources = new MetadataSources(registry);
Timings.time("RegisterDBEntities", () ->
new Reflections().getTypesAnnotatedWith(Entity.class).forEach(sources::addAnnotatedClass));
try {
Metadata metadata = sources.buildMetadata();
sessionFactory = metadata.buildSessionFactory();
} catch (Exception e) {
StandardServiceRegistryBuilder.destroy(registry);
e.printStackTrace();
}
}
示例8: buildSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
/**
* Created by admin on 10.01.2017.
* @return SessionFactory
*/
protected static SessionFactory buildSessionFactory() {
// A SessionFactory is set up once for an application!
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // configures settings from hibernate.cfg.xml
.build();
try {
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
} catch (Exception e) {
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy(registry);
throw new ExceptionInInitializerError("Initial SessionFactory failed" + e);
}
return sessionFactory;
}
示例9: buildSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
/**
* Created by admin on 30.12.2016.
* create factory
* @return SessionFactory
*/
protected static SessionFactory buildSessionFactory() {
// A SessionFactory is set up once for an application!
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // configures settings from hibernate.cfg.xml
.build();
try {
sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory();
} catch (Exception e) {
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy(registry);
throw new ExceptionInInitializerError("Initial SessionFactory failed" + e);
}
return sessionFactory;
}
示例10: setUp
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
@BeforeClass
protected void setUp() throws Exception {
// A SessionFactory is set up once for an application!
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // configures settings from hibernate.cfg.xml
.build();
try {
sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
}
catch (Exception e) {
e.printStackTrace();
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy( registry );
}
}
示例11: buildSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
private SessionFactory buildSessionFactory(String dbName) {
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.dialect",
"org.hibernate.dialect.H2Dialect");
configuration.setProperty("hibernate.connection.driver_class",
"org.h2.Driver");
configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:" + dbName);
configuration.setProperty("hibernate.hbm2ddl.auto", "create");
configuration.setProperty("hibernate.current_session_context_class", "managed");
configuration.addAnnotatedClass(TestEntity.class);
configuration.addAnnotatedClass(Phone.class);
configuration.addAnnotatedClass(Transaction.class);
configuration.addAnnotatedClass(Audit.class);
StandardServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder().applySettings(
configuration.getProperties()).build();
return configuration.buildSessionFactory(serviceRegistry);
}
示例12: buildSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
private SessionFactory buildSessionFactory(String dbName) {
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.dialect",
"org.hibernate.dialect.H2Dialect");
configuration.setProperty("hibernate.connection.driver_class",
"org.h2.Driver");
configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:" + dbName);
configuration.setProperty("hibernate.hbm2ddl.auto", "create");
configuration.setProperty("hibernate.current_session_context_class", "managed");
configuration.addAnnotatedClass(Order.class);
configuration.addAnnotatedClass(OrderItem.class);
StandardServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder().applySettings(
configuration.getProperties()).build();
return configuration.buildSessionFactory(serviceRegistry);
}
示例13: buildSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
private SessionFactory buildSessionFactory(String dbName) {
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.dialect",
"org.hibernate.dialect.H2Dialect");
configuration.setProperty("hibernate.connection.driver_class",
"org.h2.Driver");
configuration.setProperty("hibernate.connection.url", "jdbc:h2:mem:" + dbName);
configuration.setProperty("hibernate.hbm2ddl.auto", "create");
configuration.setProperty("hibernate.current_session_context_class", "managed");
configuration.addAnnotatedClass(RelationalEntity.class);
StandardServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder().applySettings(
configuration.getProperties()).build();
return configuration.buildSessionFactory(serviceRegistry);
}
示例14: setUpDb
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
@BeforeClass
public void setUpDb() throws Exception {
// A SessionFactory is set up once for an application!
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
.configure() // configures settings from hibernate.cfg.xml
.build();
try {
sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
}
catch (Exception e) {
e.printStackTrace();
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
// so destroy it manually.
StandardServiceRegistryBuilder.destroy( registry );
}
}
示例15: testCreationOfSessionFactory
import org.hibernate.boot.registry.StandardServiceRegistry; //导入依赖的package包/类
@Test
public void testCreationOfSessionFactory() {
Properties props = getProperties();
Config conf = ConfigFactory.parseProperties(props);
hs = new HibernateService(conf);
SessionFactory sf = hs.getSessionFactory();
assertNotNull(sf);
assertFalse(sf.isClosed());
// traverse through the session factory to get at configuration values
SessionFactoryOptions sfo = sf.getSessionFactoryOptions();
StandardServiceRegistry ssr = sfo.getServiceRegistry();
ConfigurationService cs = ssr.getService(ConfigurationService.class);
assertEquals(props.getProperty("hibernate.connection.driver_class"), cs.getSetting("hibernate.connection.driver_class", StandardConverters.STRING));
assertEquals(props.getProperty("hibernate.connection.url"), cs.getSetting("hibernate.connection.url", StandardConverters.STRING));
assertEquals(props.getProperty("hibernate.dialect"), cs.getSetting("hibernate.dialect", StandardConverters.STRING));
assertEquals(props.getProperty("hibernate.hbm2ddl.auto"), cs.getSetting("hibernate.hbm2ddl.auto", StandardConverters.STRING));
// check mapping
ClassMetadata cm = sf.getClassMetadata(TestObject.class);
String[] names = cm.getPropertyNames();
assertEquals(1, names.length);
assertEquals("name", names[0]);
assertEquals("string", cm.getPropertyType("name").getName());
}