Hibernate创建不带persistence.xml的JPA EntityManagerFactory

Hibernate创建不带persistence.xml的JPA EntityManagerFactory,hibernate,jpa-2.0,Hibernate,Jpa 2.0,大家好,有人知道在Hibernate 4+中从Hibernate以编程方式创建JPA EntityManagerFactory impl的首选方法吗 我用hsql来做这件事,但它没有润滑 Properties props = new Properties(); props.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect"); props.setProperty("hibernate.connec

大家好,有人知道在Hibernate 4+中从Hibernate以编程方式创建JPA EntityManagerFactory impl的首选方法吗

我用hsql来做这件事,但它没有润滑

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();
这似乎是一种新的方式,但我不断得到NPE

impl = new EntityManagerFactoryImpl(transactionType, false, 
                    clazz, config, serviceRegistry, "i_storage_tests_persistence_unit");
蒂亚,
Scott可以参考在没有xmlOk的情况下创建EntityManagerFactory,这似乎是可行的,但是我仍然有一个问题,我似乎无法用标准api
Properties=new Properties()解决;setProperty(AvailableSettings.CONNECTION_PROVIDER,“org.hibernate.ejb.CONNECTION.InjectedDataSourceConnectionProvider”);Ejb3Configuration config3=新的Ejb3Configuration();配置3.setDataSource(ds)我正在使用这种代码为单线程apache DBCP池的junit测试注入数据源,但是我可能会在生产中使用c3p0。此外,我在使用hibernate映射时遇到了一个问题(我需要这样做,因为它们工作得更好),
InputStream in=KeyValue.class.getResourceAsStream(“KeyValue.xml”);配置3.添加输出流(in)你可以用上面的细节和遇到的问题来更新帖子,这样可以帮助其他人更好地了解它。你可以参考在没有xmlOk的情况下创建EntityManagerFactory,这似乎是可行的,但是我仍然有一个问题,我似乎无法用标准api
Properties=new Properties()解决;setProperty(AvailableSettings.CONNECTION_PROVIDER,“org.hibernate.ejb.CONNECTION.InjectedDataSourceConnectionProvider”);Ejb3Configuration config3=新的Ejb3Configuration();配置3.setDataSource(ds)我正在使用这种代码为单线程apache DBCP池的junit测试注入数据源,但是我可能会在生产中使用c3p0。此外,我在使用hibernate映射时遇到了一个问题(我需要这样做,因为它们工作得更好),
InputStream in=KeyValue.class.getResourceAsStream(“KeyValue.xml”);配置3.添加输出流(in)你可以用上面的细节和遇到的问题更新帖子,这样可以帮助其他人更好地了解它