Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3360034
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:56:40+00:00 2026-05-18T02:56:40+00:00

Greetings. I’m just starting to explore Maven and I use m2eclipse as to use

  • 0

Greetings.

I’m just starting to explore Maven and I use m2eclipse as to use Maven in Eclipse.

I found that there is a hibernate-based archetype with
Group Id: com.rfc.maven.archetypes and
Artifact Id: jpa-maven-archetype

Does anybody knows if there are archetypes for OpenJPA-based projected with test frameworks included?

Thanks a lot.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:56:41+00:00Added an answer on May 18, 2026 at 2:56 am

    Does anybody knows if there are archetypes for OpenJPA-based projected with test frameworks included?

    Not to my knowledge. So my suggestion would be to use the jpa-maven-archetype and to tweak it for OpenJPA and JPA 2.0.

    First, generate a project:

    $ mvn archetype:generate \
      -DgroupId=com.stackoverflow \
      -DartifactId=Q4161012 \
      -DpackageName=com.stackoverflow.domain \
      -DarchetypeGroupId=com.rfc.maven.archetypes \
      -DarchetypeArtifactId=jpa-maven-archetype  \
      -DarchetypeVersion=1.0.0 \
      -DremoteRepositories=http://maven.rodcoffin.com/repo \
      -DinteractiveMode=false
    

    Then cd into the created directory and modify the pom.xml to replace Hibernate by OpenJPA artifacts, add the OpenJPA plugin for enhancement (I did a few other minor tweaks):

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.stackoverflow</groupId>
      <artifactId>Q4161012</artifactId>
      <version>1.0-SNAPSHOT</version>
      <name>JPA Project</name>
      <properties>
        <openjpa.version>2.0.1</openjpa.version>
        <slf4j.version>1.6.1</slf4j.version>
      </properties>
      <dependencies>
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>4.8.2</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.dbunit</groupId>
          <artifactId>dbunit</artifactId>
          <version>2.4.8</version>
          <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>org.apache.openjpa</groupId>
          <artifactId>openjpa</artifactId>
          <version>${openjpa.version}</version>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
          <version>${slf4j.version}</version>
        </dependency>
        <dependency>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-simple</artifactId>
          <version>${slf4j.version}</version>
        </dependency>
        <dependency>
          <groupId>hsqldb</groupId>
          <artifactId>hsqldb</artifactId>
          <version>1.8.0.7</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
              <source>1.6</source>
              <target>1.6</target>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>openjpa-maven-plugin</artifactId>
            <version>1.1</version>
            <configuration>
              <includes>com/stackoverflow/domain/**/*.class</includes>
              <addDefaultConstructor>true</addDefaultConstructor>
              <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
              <!-- Pass additional properties to the Plugin here -->
              <toolProperties>
                <property>
                  <name>directory</name>
                  <value>otherdirectoryvalue</value>
                </property>
              </toolProperties>
            </configuration>
            <executions>
              <execution>
                <id>enhancer</id>
                <phase>process-classes</phase>
                <goals>
                  <goal>enhance</goal>
                </goals>
              </execution>
            </executions>
            <dependencies>
              <dependency>
                <groupId>org.apache.openjpa</groupId>
                <artifactId>openjpa</artifactId>
                <version>${openjpa.version}</version>
              </dependency>
            </dependencies>
          </plugin>
        </plugins>
      </build>
    </project>
    

    Then modify the persistence.xml for JPA 2.0 and add the OpenJPA specific properties:

    <persistence xmlns="http://java.sun.com/xml/ns/persistence" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
      version="2.0">
        <persistence-unit name="Q4161012"></persistence-unit>
        <persistence-unit name="Q4161012-test"
            transaction-type="RESOURCE_LOCAL">
            <class>com.stackoverflow.domain.User</class>
            <properties>
                <property name="javax.persistence.jdbc.driver"
                    value="org.hsqldb.jdbcDriver" />
                <property name="javax.persistence.jdbc.url"
                    value="jdbc:hsqldb:mem:my-project-test" />
                <property name="javax.persistence.jdbc.user" value="sa" />
                <property name="javax.persistence.jdbc.password" value="" />
    
                <property name="openjpa.jdbc.DBDictionary"
                    value="org.apache.openjpa.jdbc.sql.HSQLDictionary" />
                <property name="openjpa.jdbc.SynchronizeMappings"
                    value="buildSchema(SchemaAction=add)"/>
            </properties>
        </persistence-unit>
    </persistence>
    

    And replace the following lines in UserTest.java (and clean up imports):

    HibernateEntityManager em = (HibernateEntityManager) emf.createEntityManager();
    
    DbUnitDataLoader loader = new DbUnitDataLoader(testData, em.getSession().connection());
    

    By (OpenJPA doesn’t support the EntityManager#unwrap(Object) from JPA 2.0 yet, see OPENJPA-1803, so you have to use OpenJPA specific classes):

    EntityManager em = emf.createEntityManager();
    OpenJPAEntityManager oem = OpenJPAPersistence.cast(em);
    Connection conn = (Connection) oem.getConnection(); 
    conn.setAutoCommit(true);
    
    DbUnitDataLoader loader = new DbUnitDataLoader(testData, conn);
    

    And run the test:

    $ mvn clean test
    [INFO] Scanning for projects...
    ...
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESSFUL
    [INFO] ------------------------------------------------------------------------
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Greetings Overflowers, Is there an SQL DBMS that allows me to create an indexed
Greetings! I have a Repeater control that's using an XmlDataSource control. <asp:FormView id=myFormView runat=server
Greetings! I'm trying to have a UIWebView controlled from generated events. Is there a
Greetings all, Is there a built in way to know when a user is
Greetings, I'm confused as to the best approach to make when consuming REST based
Greetings, I'm working on a game project that uses a 3D variant of hexagonal
Greetings, I have an asp.net mvc application. I have some links that corresponds to
Greetings Stack Overflow community. I'm trying to make a function that can pop all
Greetings all, Is there any issue in the following logic for allocating 2D array:
Greetings, I have a view based application project where I have created an NSObject

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.