实体抛出没有方法异常

时间:2014-08-05 15:03:43

标签: entity eclipselink jpa-2.0 java-ee-7

我正在构建一个简单的JavaEE项目,并且我不断收到NoMethodFoundException:Faculty._persistence_set_customers(Customer)。

教师实体与客户实体之间存在oneToMany关系。当我删除这种关系时,异常消失了。这可能是什么原因?为什么要求这种方法?

例外情况如下:

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)

Faculty实体的源代码如下:

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

}

非常感谢,

1 个答案:

答案 0 :(得分:0)

检查一些示例代码后:我意识到与OneToMany或ManyToMany相关的所有关系都使用List&lt;&gt;而不是ArrayList&lt;&gt;。在进行此更改后,应用程序工作正常,但原因仍然未知。