本文整理匯總了Java中org.hibernate.boot.MetadataSources類的典型用法代碼示例。如果您正苦於以下問題:Java MetadataSources類的具體用法?Java MetadataSources怎麽用?Java MetadataSources使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
MetadataSources類屬於org.hibernate.boot包,在下文中一共展示了MetadataSources類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSessionFactory
import org.hibernate.boot.MetadataSources; //導入依賴的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.MetadataSources; //導入依賴的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.MetadataSources; //導入依賴的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: HibernateUserDao
import org.hibernate.boot.MetadataSources; //導入依賴的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);
// }
}
示例5: setUp
import org.hibernate.boot.MetadataSources; //導入依賴的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 );
}
}
示例6: start
import org.hibernate.boot.MetadataSources; //導入依賴的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();
}
}
示例7: buildSessionFactory
import org.hibernate.boot.MetadataSources; //導入依賴的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;
}
示例8: buildSessionFactory
import org.hibernate.boot.MetadataSources; //導入依賴的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;
}
示例9: setUp
import org.hibernate.boot.MetadataSources; //導入依賴的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 );
}
}
示例10: bootstrapping
import org.hibernate.boot.MetadataSources; //導入依賴的package包/類
@Test
public void bootstrapping() {
log.info("... bootstrapping ...");
ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().configure().build();
SessionFactory sessionFactory = new MetadataSources(standardRegistry)
.addAnnotatedClass(Author.class).buildMetadata()
.buildSessionFactory();
Session session = sessionFactory.openSession();
session.beginTransaction();
Author a = new Author();
a.setFirstName("Thorben");
a.setLastName("Janssen");
session.persist(a);
session.getTransaction().commit();
session.close();
}
示例11: setUpDb
import org.hibernate.boot.MetadataSources; //導入依賴的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 );
}
}
示例12: setup
import org.hibernate.boot.MetadataSources; //導入依賴的package包/類
@Before
public void setup() {
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
.applySetting( "hibernate.show_sql", "true" )
.applySetting( "hibernate.format_sql", "true" )
.applySetting( "hibernate.hbm2ddl.auto", "update" )
.applySetting( "hibernate.dialect", "org.hibernate.dialect.H2Dialect" )
.applySetting( "hibernate.connection.driver_class", "org.h2.Driver" )
.applySetting( "hibernate.connection.url", "jdbc:h2:mem:testdbHibernate" )
.applySetting( "hibernate.connection.username", "sa" )
.applySetting( "hibernate.connection.password", "" )
.applySetting( "hibernate.use_sql_comment", "true" )
;
Metadata metadata = null;
if(packageBase()== null){
metadata= new MetadataSources( srb.build() ).addAnnotatedClass(getEntityClass()).buildMetadata();
}else{
metadata= new MetadataSources( srb.build() )
.addAnnotatedClass(Item.class)
.addAnnotatedClass(Offer.class)
.addPackage(packageBase()).buildMetadata();
}
sf = metadata.buildSessionFactory();
}
示例13: setup
import org.hibernate.boot.MetadataSources; //導入依賴的package包/類
@BeforeClass
public static void setup() {
// @formatter:off
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
.applySetting("hibernate.show_sql", "true")
.applySetting("hibernate.format_sql", "true")
.applySetting("hibernate.hbm2ddl.auto", "update")
.applySetting("use_sql_comments", "true")
.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
.applySetting("hibernate.connection.driver_class", "org.h2.Driver")
.applySetting("hibernate.connection.url", "jdbc:h2:mem:testdbHibernate")
.applySetting("hibernate.connection.username", "sa")
.applySetting("hibernate.connection.password", "")
.applySetting("hibernate.use_sql_comment", "true");
Metadata metadata = null;
log.info("+++ setup");
metadata = new MetadataSources(srb.build()).addAnnotatedClass(EmailMessage.class).addAnnotatedClass(Email.class).buildMetadata();
sf = metadata.buildSessionFactory();
// @formatter:on
}
示例14: setup
import org.hibernate.boot.MetadataSources; //導入依賴的package包/類
@BeforeClass
public static void setup() {
// @formatter:off
StandardServiceRegistryBuilder srb = new StandardServiceRegistryBuilder()
.applySetting("hibernate.show_sql", "true")
.applySetting("hibernate.format_sql", "true")
.applySetting("hibernate.hbm2ddl.auto", "update")
.applySetting("use_sql_comments", "true")
.applySetting("hibernate.dialect", "org.hibernate.dialect.H2Dialect")
.applySetting("hibernate.connection.driver_class", "org.h2.Driver")
.applySetting("hibernate.connection.url", "jdbc:h2:mem:testdbHibernate")
.applySetting("hibernate.connection.username", "sa")
.applySetting("hibernate.connection.password", "")
.applySetting("hibernate.use_sql_comment", "true");
Metadata metadata = null;
log.info("+++ setup");
metadata = new MetadataSources(srb.build()).addAnnotatedClass(Address.class).addAnnotatedClass(User.class).buildMetadata();
sf = metadata.buildSessionFactory();
// @formatter:on
}
示例15: HibernateDatabase
import org.hibernate.boot.MetadataSources; //導入依賴的package包/類
public HibernateDatabase(Properties properties) throws HibernateException {
StandardServiceRegistry registry = new StandardServiceRegistryBuilder().applySettings(properties).build();
MetadataSources metadataSources = new MetadataSources(registry);
metadataSources.addAnnotatedClass(SystemInfo.class)
.addAnnotatedClass(Project.class)
.addAnnotatedClass(Runner.class)
.addAnnotatedClass(Repository.class)
.addAnnotatedClass(RepositoryType.class)
.addAnnotatedClass(SystemUnderTest.class)
.addAnnotatedClass(Requirement.class)
.addAnnotatedClass(Specification.class)
.addAnnotatedClass(Reference.class)
.addAnnotatedClass(Execution.class);
this.properties = properties;
this.metadata = metadataSources.buildMetadata();
}