1
votes

I have two entities working in Mater Detail pattern like i describe in:

Stackoverflow Post: jpa-eclipselink-onetomany-derived-ids-fail

The pattern works as expected with LOCAL RESOURCE, but when i try to move the example to a web environment GlassFish4.1 (JSF) with JTA, i get the following error:

Advertencia: DTX5014: Caught exception in beforeCompletion() callback: java.lang.NullPointerException at entidades.OrderItemPK._persistence_set(OrderItemPK.java)

The source code for persistence class:

import java.util.List;
import javax.persistence.Query;
import javax.persistence.EntityManager;
import java.util.List;
import javax.persistence.Query;
import javax.persistence.EntityManager;


public abstract class AbstractFacade<T> {

    private Class<T> entityClass;
    protected abstract EntityManager getEntityManager();    

    public AbstractFacade(Class<T> entityClass) {
    this.entityClass = entityClass;
    }

    public void create(T entity) {
    getEntityManager().persist(entity);
    }

    public T edit(T entity) {
    return getEntityManager().merge(entity);
    }

    public void remove(T entity) {
    getEntityManager().remove(getEntityManager().merge(entity));
    }

I tried with both methods create and edit. Any idea what I'm doing wrong, suggestions are welcome.

2
Assuming you are using the mapsId example with an embeddable, when does this error occur? ie when you create a new instance, or edit an existing one? If it is an existing instance that has been modified, how are you reading it in and what changes are being made? Does the same problem occur if you use a PK class instead of embeddedId?Chris
All entities are new instances, so far I've stuck with the method "create", I can not get it work, nor I could make it work mapping entities with PK ClassHickaru

2 Answers

1
votes

Your entity is using the basic 'long' types which do not allow null, so check that your database values are not null. If they are, a quick fix is to change the to the wrapper type "Long": http://edwin.baculsoft.com/2012/02/nullpointerexception-when-using-jpa/ If that is the case, you will need to track down how the database is being populated with null values for fields associated to the primary key.

1
votes

The problem was in the PK class, change the data type int to Integer and then the error appeared on the method hashCode()