2012-03-26 10 views
0

私はstruts2とopenJPAを使ってビルドしているプロジェクトを持っています。私はいくつかの統合テストをしたいと思っていますが、問題を抱えているようです。統合OpenJPAデータアクセスオブジェクトまたはサービスファサードのテスト?

persistence.xmlの

<persistence-unit name="SalesCertIT" transaction-type="RESOURCE_LOCAL"> 
    <jta-data-source>jdbc/salesCertIT</jta-data-source> 
    <class>com.ist.salesCert.entities.Certification</class> 
    <properties> 
     <property name="log4j" value="DefaultLevel=WARN, Runtime=INFO, Tool=INFO, SQL=TRACE" /> 
     <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" /> 
     <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/sales_certification" /> 
     <property name="openjpa.ConnectionUserName" value="dev" /> 
     <property name="openjpa.ConnectionPassword" value="password" /> 
     <property name="openjpa.Id" value="SalesCertIT" /> 
     <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver" /> 
    </properties> 
</persistence-unit> 

クラス:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("SalesCertIT"); 
EntityManager em = emf.createEntityManager(); 

私はエラーを取得する:私はpersistence.xmlのとMySQLコネクタ - Javaの両方を追加しました

A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.

- * -stable-bin-jarをクラスパスに追加する(Eclipse-> debug Configuration-> Class path->ブートストラップエントリ)

私は、実行時にそれを設定しようとした場合には、作業を行いますが、操作を実行しようとしたとき、私は別のエラーを取得:

HashMap<String, String> conf = new HashMap<String, String>(); 
conf.put("openjpa.ConnectionDriverName", "com.mysql.jdbc.Driver"); 
conf.put("openjpa.ConnectionURL", "jdbc:mysql://localhost:3306/sales_certification"); 
conf.put("openjpa.ConnectionUserName", "dev"); 
conf.put("openjpa.ConnectionPassword", "password"); 
conf.put("openjpa.TransactionMode", "local"); 
conf.put("openjpa.Id", "SalesCertIT");  
EntityManagerFactory emf = Persistence.createEntityManagerFactory("SalesCertIT", conf); 
EntityManager em = emf.createEntityManager(); 

The type "class com.ist.salesCert.entities.Certification" has not been enhanced.

私はjavaagentを追加しようとしました引数:(Eclipse->デバッグ設定 - > Arguments-> VM引数)

-javaagent:C:/Progra~1/IBM/WebSphere/AppServer/plugins/com.ibm.ws.jpa.jar

この時点では、私がしようとする他に何かわかりません。何か案は?

+0

これをJSEまたはJEEで実行しようとしていますか?最初の設定セクションで、なぜopenjpa.ConnectionDriverNameプロパティが複数あるのですか?あなたのテストが実行されるとき、xyz以外の他の意味のあるメッセージは強化されていませんか? – Rick

答えて

0

私はJEE6仕様を遵守しようとしていましたが、websphere 7のopenjpa 2はJ2EEです。

 <!-- openjpa plugin --> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>openjpa-maven-plugin</artifactId> 
      <version>1.2</version> 
      <configuration> 
       <includes>com/ist/salesCert/entities/*.class</includes> 
       <excludes>com/ist/salesCert/entitles/Quarters.class</excludes> 
       <addDefaultConstructor>true</addDefaultConstructor> 
       <enforcePropertyRestrictions>true</enforcePropertyRestrictions> 
       <persistenceXmlFile>WebRoot/META-INF/persistence.xml</persistenceXmlFile> 
       <detail>true</detail> 
      </configuration> 
      <executions> 
       <execution> 
        <id>enhancer</id> 
        <phase>process-classes</phase> 
        <goals> 
         <goal>enhance</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

次に、このコマンドは、エンティティ高めるであろう:

mvn openjpa:enhance 

注:私は私のOpenJPAのエンティティを強化することが分かっ 究極のソリューションは、OpenJPAのプラグインでMavenを使用していたというなければならない他の依存関係がありますpom.xmlファイルにある