JPA QueryException:要插入表中的字段列表为空

时间:2013-06-21 07:02:59

标签: jpa

我实际上遇到了JPA的问题。他抱怨一个 我的实体:

javax.persistence.RollbackException: Exception [EclipseLink-6023] (Eclipse Persistence Services - 2.3.2.v20111125-r10461): org.eclipse.persistence.exceptions.QueryException
Exception Description: The list of fields to insert into the table [DatabaseTable(TBL_SPJ_CAST_MOVIE)] is empty.  You must define at least one mapping for this table.

经过一番研究后我发现这个例外出现了 由于当然,在Entity classe中没有定义任何列 你无法将数据插入空表。

但实际上我的实体中定义了两列。一个为身份证 和一个用于m:n表的外键:

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name="TBL_SPJ_CAST_MOVIE")
public class CastMovie implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="CAST_MOVIE_ID", unique=true)
    private int castID = 0;
    @ManyToMany(fetch=FetchType.LAZY, cascade={CascadeType.ALL})
    @JoinTable(name="TBL_SPJ_CAST_ROLE", joinColumns={@JoinColumn(name="CAST_MOVIE_ID")}, inverseJoinColumns={@JoinColumn(name="ROLE_ID")})
    private List<Role> roles = null;

    public CastMovie() {}

    public int getCastID() {
        return castID;
    }
    public void setCastID(int castID) {
        this.castID = castID;
    }
    public List<Role> getRoles() {
        return roles;
    }
    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }
}

那么这个错误的重点是什么?所有来自xml文件的数据都让我无法理解 放入更多列(如果那就是问题)。

编辑:

以下是此问题涉及的四个表的结构:

enter image description here

  • 一部电影有一个演员 - &gt;关系一对一
  • 许多演员有很多Rols - &gt;关系多对多

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题 将ID字段的GenerationType设置为GenerationType.TABLE,它就可以了 另请阅读this