我正在为我的域类使用eclipse Texo项目,我已将其移至Play 2.3.8。
我根据此https://www.playframework.com/documentation/2.3.8/JavaJPA添加
进行配置 <non-jta-data-source>pssh2</non-jta-data-source>
到我现有的persistance.xml
我添加了一个GlobalSettings子类来初始化DaoRegistry,如下所示:
public void beforeStart(Application app) {
Logger.info("Application has started");
Properties prop = getProperties();
ParcelSystemSimulationModelPackage.initialize();
EntityManagerFactory emf = Persistence.createEntityManagerFactory(prop.getProperty("persistname"));
EntityManager em = emf.createEntityManager();
EntityManagerProvider.getInstance().setEntityManagerFactory(emf);
EntityManagerProvider.getInstance().setCurrentEntityManager(em);
EntityManagerProvider.getInstance().setUseCurrentEntityManagerPattern(true);
将ecore文件移动到jar中并将其放入lib目录中。它初始化Texo生成的ModelPackage。但它找不到上面源代码中createEntityManager行所需的数据源。我明白了:
Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-7060] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Cannot acquire data source [pssh2].
Internal Exception: javax.naming.NameNotFoundException: pssh2 not found
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:762) ~[eclipselink-2.5.0.jar:2.5.0.v20130507-3faac2b]
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.getAbstractSession(EntityManagerFactoryDelegate.java:204) ~[eclipselink-2.5.0.jar:2.5.0.v20130507-3faac2b]
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryDelegate.createEntityManagerImpl(EntityManagerFactoryDelegate.java:304) ~[eclipselink-2.5.0.jar:2.5.0.v20130507-3faac2b]
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:336) ~[eclipselink-2.5.0.jar:2.5.0.v20130507-3faac2b]
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:302) ~[eclipselink-2.5.0.jar:2.5.0.v20130507-3faac2b]
at com.example.pss.Global.beforeStart(Global.java:44) ~[na:na]
我在application.conf文件中设置了数据源,如下所示:
db.default.driver=org.h2.Driver
db.default.url="jdbc:h2:file://C:/Users/david.wynter/git/pss/db/pss_db; DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE"
db.default.user="sa"
db.default.password="*******"
#
# You can expose this datasource via JNDI if needed (Useful for JPA)
db.default.jndiName=pssh2
jpa.default=pssh2