2012-03-26 2 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의 커넥터 - 자바를 모두 추가 한

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

- * -stable-bin-jar을 클래스 경로에 추가합니다 (Eclipse-> 디버그 구성 -> 클래스 경로 생성> 부트 스트랩 항목)

나는 그것이 작동합니까 런타임에 구성하려고하지만 나는이 작업을 수행하려고 또 다른 오류가 발생하는 경우는 :

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-> 디버그 구성 -> 인수 -> 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입니다.

mvn openjpa:enhance 

참고 :이해야 다른 종속성이 그런 다음이 명령은 엔티티를 향상 할

 <!-- 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> 

: 내는 OpenJPA 엔티티를 강화하는 것으로 궁극적 인 해결책은는 OpenJPA의 플러그인을 받는다는을 사용하는 것이 었습니다 pom.xml 파일에 있습니다.