私は 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>
インメモリデータベースを操作するために、2 番目の永続ユニットを変更するにはどうすればよいですか?
EDIT: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 レイヤー サービス:
@Stateless
public class EntityDao implements EntityDaoLocal {
@PersistenceContext
private EntityManager em;
}