我有一个Java应用程序,我曾经在内存Derby驱动程序中使用此持久性单元进行测试:
<persistence-unit name="TestPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.connection.url" value="jdbc:derby:memory:ProjectDB"/>
<property name="hibernate.connection.driver_class" value="org.apache.derby.jdbc.EmbeddedDriver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.connection.username" value=""/>
<property name="hibernate.connection.password" value=""/>
</properties>
现在我添加了一个EJB服务层,因此我无法在内存数据库中使用相同的工作持久性单元。以下工作正常,但我想把它留在内存中
<persistence-unit name="moduleNamePU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/sample</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
</properties>
如何更改第二个持久性单元以便在内存db中使用?
编辑:作为EJB容器,我使用Glassfish 3.1
实体服务:
@Stateless
@Local(value=EntityServiceLocal.class)
public class EntityService implements EntityServiceLocal {
@EJB
private EntityDaoLocal entityDao;
@Resource
private SessionContext ctx;
public void setEntityDao(EntityDaoLocal entityDao) {
this.entityDao = entityDao;
}
}
Dao Layer服务:
@Stateless
public class EntityDao implements EntityDaoLocal {
@PersistenceContext
private EntityManager em;
}