0
votes

I have a project I'm building using struts2 and openJPA. I want to do some integration testing but I seem to be having an issue getting it to work.

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>

class:

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

I get the error:

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

I've added both the persistence.xml and mysql-connector-java-*-stable-bin-jar to the classpath, (Eclipse->debug Configuration->Classpath->Bootstrap entries)

If I try to configure it at runtime it does work but then I get another error when trying to perform an operation:

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.

I tried to add a javaagent argument: (Eclipse->Debug Configurations->Arguments->VM arguments)

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

At this point I don't know what else to try. Any ideas?

1
Are you trying to run this in JSE or JEE? In your first configuration section, why do you have multiple openjpa.ConnectionDriverName properties? When your test runs, are there any other meaningful messages other than xyz has not been enhanced?Rick

1 Answers

0
votes

One problem was that I was trying to adherer to the JEE6 specs but openjpa 2 on websphere 7 is J2EE. The ultimate solution I found to enhancing my openjpa entities was to use maven with the openjpa plugin:

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

Then this command would enhance the entities:

mvn openjpa:enhance

Note: there are other dependencies that must be in the pom.xml file