Search code examples
entityeclipselinkjpa-2.0java-ee-7

Entity throw no method exception


I am building a simple JavaEE project and I keep getting the NoMethodFoundException: Faculty._persistence_set_customers(Customer).

The faculty entity has a oneToMany relationship with Customer entity. And the exception disappear when I removes that relationship. What could be the reason for this? Why is it asking for this method?

The exception is as followed:

Caused by: javax.persistence.PersistenceException: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.DescriptorException
Exception Description: An internal error occurred while accessing method [_persistence_set_customers] on class [class hb.model.entity.Faculty].
Internal Exception: java.lang.NoSuchMethodException: hb.model.entity.Faculty._persistence_set_customers(hb.model.entity.Customer)
Descriptor: RelationalDescriptor(hb.model.entity.Faculty --> [DatabaseTable(USERS)])
    at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl$1.handleException(EntityManagerSetupImpl.java:692)
    at org.eclipse.persistence.transaction.AbstractSynchronizationListener.handleException(AbstractSynchronizationListener.java:275)
    at org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:170)
    at org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)
    at com.sun.enterprise.transaction.JavaEETransactionImpl.commit(JavaEETransactionImpl.java:452)

The source code of the Faculty entity is as followed:

package hb.model.entity;

import java.io.Serializable;
import java.util.ArrayList;
import javax.persistence.Entity;
import javax.persistence.OneToMany;

/**
 *
 * @author hasee
 */
@Entity
public class Faculty extends Users implements Serializable {

    private static final long serialVersionUID = 1L;

    @OneToMany(mappedBy = "faculty")
    private ArrayList<Customer> customers;

    private String position;

    public Faculty() {
    }

    public ArrayList<Customer> getCustomers() {
        return customers;
    }

    public void setCustomers(ArrayList<Customer> customers) {
        this.customers = customers;
    }



    public String getPosition() {
        return position;
    }

    public void setPosition(String position) {
        this.position = position;
    }

}

Many thanks,


Solution

  • After checking some example code: I realize all the relationship related to OneToMany or ManyToMany use List<> instead of ArrayList<>. After making this change the application worked just fine, however the reason is still unknown.