我正在使用DataNucleus作为DAO层开发Web应用程序(主要是由于历史原因)。它在Payara服务器内运行(Glassfish 4前叉) 它工作正常,但现在我想使用JNDI数据库连接池来获取DataNucleus的PersistenceManagerFactory。 从文档中,似乎以下代码就足够了:
pmf = JDOHelper.getPersistenceManagerFactory( "jdbc/HxWmDb", context );
但这样我启动应用程序时出错(DbSession是实现DAO层的类,错误行正好是上面的那个):
Caused by: java.lang.ClassCastException
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:262)
at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:150)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:1791)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(JDOHelper.java:1755)
at ejb.DbSession.<init>(DbSession.java:119)
...
Caused by: java.lang.ClassCastException: com.sun.gjc.spi.jdbc40.DataSource40 cannot be cast to org.omg.CORBA.Object
at com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:245)
有什么建议吗?
根据DN1的要求进行少量更新:
作为第一种方法,我尝试了链接中描述的内容:
Properties properties = new Properties();
properties.setProperty("datanucleus.ConnectionFactoryName","jdbc/HxWmDb");
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(properties);
如前所述,错误是无论如何都需要URI:
Caused by: org.datanucleus.exceptions.NucleusException: You haven't specified persistence property 'datanucleus.ConnectionURL'