Hibernate create JPA EntityManagerFactory with out persistence.xml

旧街凉风 提交于 2019-12-11 02:18:37

问题


Hi does anyone know what the preferred way to do programmatically create a JPA EntityManagerFactory impl from Hibernate in Hibernate 4+?

I used hsql to do this, but its depricated;

Properties props = new Properties();
props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect");
props.setProperty("hibernate.connection.driver_class", "org.hsqldb.jdbcDriver"); 
props.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:aname");
props.setProperty("hibernate.connection.username", "sa" );  
props.setProperty("hibernate.connection.password", "" );        

Ejb3Configuration config3 = new Ejb3Configuration();
config3.setProperties(props);
config3.addFile("src/org/adligo/i/storage/entities/keyValue.xml");
impl = config3.buildEntityManagerFactory();

This seems to be the new way, but I keep getting NPEs;

impl = new EntityManagerFactoryImpl(transactionType, false, 
                    clazz, config, serviceRegistry, "i_storage_tests_persistence_unit");

TIA, Scott

来源:https://stackoverflow.com/questions/9947532/hibernate-create-jpa-entitymanagerfactory-with-out-persistence-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!