Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JTA Persistence issue (Null Pointer Exception)(I get null pointer exception when i try to persist oneToMany relationship)
JTA Persistence issue (Null Pointer Exception) [message #1677788] Mon, 16 March 2015 01:44 Go to next message
Matias Panasci is currently offline Matias PanasciFriend
Messages: 7
Registered: March 2015
Junior Member
I have two entities working in Master-Detail pattern like this:

index.php/fa/21189/0/

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:

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

this source code works
    public static void main(String[] args) {
        factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
        EntityManager em = factory.createEntityManager();
        
        em.getTransaction().begin();
        
        // Fill the items filds
        OrderItem item = new OrderItem();
        item.setItemDesc("Item Text");

        // Fill the orders fields
        CustomerOrder order = new CustomerOrder();
        order.setOrderText("Order text");
        
        // Fill the relationship fields
        order.getOrderItemCollection().add(item);
        item.setCustomerOrder(order);        
        
        em.persist(order);
        em.getTransaction().commit();
    }


this source code doesn't work
    public void CreateOrder(){
    
        // Fill the items filds
        OrderItem item = new OrderItem();
        item.setItemDesc("Item Text");

        // Fill the orders fields
        CustomerOrder order = new CustomerOrder();
        order.setOrderText("Order text");
        
        // Fill the relationship fields
        order.getOrderItemCollection().add(item);
        item.setCustomerOrder(order);    
        
       // Save the changes
        this.create(order) ;
    }


The source code for persistence class of web enviroment:

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));
    }

 ... more code

I tried with both methods:
getEntityManager().persist(entity); 

and
getEntityManager().merge(entity);


I think the problem has to be the type of datasource, because in a java application works and in glassfish does not.
Any idea what I'm doing wrong, suggestions are welcome.
  • Attachment: bd.png
    (Size: 36.69KB, Downloaded 1913 times)
Re: JTA Persistence issue (Null Pointer Exception) [message #1681963 is a reply to message #1677788] Tue, 17 March 2015 14:38 Go to previous message
Matias Panasci is currently offline Matias PanasciFriend
Messages: 7
Registered: March 2015
Junior Member
The problem was in the PK class, change the data type int to Integer and then the error appeared on the method hashCode()
Previous Topic:@AttributeOverride at class level for inhereted map attribute
Next Topic:Unabled to set derived IDs
Goto Forum:
  


Current Time: Sun Mar 03 00:34:14 GMT 2024

Powered by FUDForum. Page generated in 0.02371 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top