これは私のSLSBです:
@Stateless
public class MyService {
PersistenceContext(unitName = "abc")
EntityManager em;
public boolean exists(int id) {
return this.em.find(Employee.class, id) != null;
}
}
これは私のものpersistence.xml
です(私はGlassfish v3を使用しています):
<persistence>
<persistence-unit name="abc">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/MyDS</jta-data-source>
<properties>
<property name="hibernate.archive.autodetection" value="class" />
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLInnoDBDialect" />
</properties>
</persistence-unit>
</persistence>
現在、OpenEJB組み込みコンテナーを使用してテストを作成しようとしています。これは私のテストクラスです:
class MyServiceText {
@Test
public void testChecksExistence() throws Exception {
Properties properties = new Properties();
properties.setProperty(
javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.client.LocalInitialContextFactory"
);
InitialContext ic = new InitialContext(properties);
// actual testing skipped
}
}
テストにはHSQLを使用したいと思います。"abc"
テスト中に永続ユニットがHSQLを指す必要があることをOpenEJBに指示するにはどうすればよいですか?新しいバージョンを作成しpersistence.xml
ませんか?使いましょopenejb.xml
うか?私は彼らの例とドキュメントで迷子になっています..:(
これはMaven-3プロジェクトです。