As described in the Problem Reporting guide to reproduce problems we need something in a neutral format. Here we define our accepted format for JPA usage. Note that By attaching a test case to DataNucleus JIRA, you hereby agree that it is a contribution to DataNucleus under the terms of the Apache 2.0 License.
|
DataNucleus provides a template JUnit GitHub project at datanucleus/test-jpa. Please fork this and mention the location of your fork on the JIRA issue that it relates to. Note that there are two JUnit tests in the provided project, one for single-threaded and one for multi-threaded issues; use the one appropriate to your case. |
As an alternative to the above, and where you are familiar with JUnit and are willing to look at the existing DataNucleus unit tests in SVN then please create a JUnit test case that utilises our existing suite of sample data etc. If you provide a testcase in this way your testcase should be a patch against current SVN trunk of the respective test suite project and it should be attached to the JIRA issue to which it relates. To add a JUnit testcase, please follow the new unit test guide
The final way is what we traditionally used to keep it build system independent and most convenient to many people. This is as follows
The above can then be put in a zip file and attached to the JIRA issue or Forum thread. The zip file should look like this. If it doesnt then you will likely be asked to repackage it. Using something other than zip (or gz) is non-portable so not accepted.
META-INF/persistence.xml META-INF/orm.xml org/ org/datanucleus/ org/datanucleus/test/ org/datanucleus/test/MyClass1.java org/datanucleus/test/MyClass2.java org/datanucleus/test/Main.java
As an alternative to the above, and where you are familiar with JUnit and are willing to look at the existing DataNucleus unit tests in SVN, then please create a JUnit test case that utilises our existing suite of sample data etc. If you provide a testcase in this way your testcase should be a patch against current SVN trunk. Again, this should be attached to the JIRA issue to which it relates. To add a JUnit testcase, please follow the new unit test guide
DataNucleus provides a template JUnit GitHub project at datanucleus/test-jpa. Please fork this and mention the location of your fork on the JIRA issue that it relates to.
A template persistence.xml is shown below. Use this as a framework
<?xml version="1.0" encoding="UTF-8" ?>
<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_1_0.xsd" version="1.0">
<!-- Test "unit", containing all classes so we can enhance the lot -->
<persistence-unit name="JPATest">
<properties>
<property name="javax.persistence.jdbc.driver" value="org.hsqldb.jdbcDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:hsqldb:mem:nucleus" />
<property name="javax.persistence.jdbc.user" value="sa" />
<property name="javax.persistence.jdbc.password" value="" />
</properties>
</persistence-unit>
</persistence>A template Main.java for JPA is shown below. Use this as a framework
package org.datanucleus.test;
import java.util.*;
import javax.persistence.*;
import org.datanucleus.util.*;
public class Main
{
static public void main(String[] args)
{
EntityManagerFactory emf = Persistence.createEntityManagerFactory("Test", null);
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try
{
tx.begin();
... (replace this with your code to persist your objects required to reproduce the problem)
MyClass myobj = new MyClass("name");
em.persist(myobj);
tx.commit();
}
catch (Exception e)
{
NucleusLogger.GENERAL.error(">> Exception thrown persisting objects", e);
return;
}
finally
{
if (tx.isActive())
{
tx.rollback();
}
em.close();
}
em = emf.createEntityManager();
tx = em.getTransaction();
try
{
tx.begin();
... (add your code here to perform the operations to demonstrate the problem)
tx.commit();
}
catch (Exception e)
{
NucleusLogger.GENERAL.error(">> Exception thrown retrieving objects", e);
return;
}
finally
{
if (tx.isActive())
{
tx.rollback();
}
em.close();
}
}
}