2

我有 2 个实体类 ParameterGroupBean 和 GroupLevelBean

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;


@Entity
@Table(name="tbl_ParameterGroups")
public class ParameterGroupBean {


@Id
@GeneratedValue
private int ParameterGroupId;
private String ParameterGroupName;  
private Boolean Status;

@ManyToOne
@JoinColumn(name="LevelId")
private GroupLevelBean level = new GroupLevelBean();

public GroupLevelBean getLevel() {
    return level;
}

public void setLevel(GroupLevelBean level) {
    this.level = level;
}

@Id
@GeneratedValue
public int getParameterGroupId() {
    return ParameterGroupId;
}

public void setParameterGroupId(int parameterGroupId) {
    ParameterGroupId = parameterGroupId;
}

@Column(length=120) 
public String getParameterGroupName() {
    return ParameterGroupName;
}

public void setParameterGroupName(String parameterGroupName) {
    ParameterGroupName = parameterGroupName;
}

public Boolean getStatus() {
    return Status;
}

public void setStatus(Boolean Status) {
    this.Status = Status;
}
}

GroupLevelBean:

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Collection;


@Entity
@Table(name="tbl_GroupLevel")
public class GroupLevelBean {

private int LevelId;
private String LevelName;
@OneToMany(mappedBy = "level")
private Collection<ParameterGroupBean> parameterGroups = new ArrayList<ParameterGroupBean>();


public Collection<ParameterGroupBean> getParameterGroups() {
    return parameterGroups;
}

public void setParameterGroups(Collection<ParameterGroupBean> parameterGroups) {
    this.parameterGroups = parameterGroups;
}


@Id
@GeneratedValue
public int getLevelId() {
    return LevelId;
}
public void setLevelId(int levelId) {
    LevelId = levelId;
}
@Column(length = 30)
public String getLevelName() {
    return LevelName;
}
public void setLevelName(String levelName) {
    LevelName = levelName;
}   
}

GroupLevelBean 和 ParameterGroupBean 之间的关系是一对多的。当我尝试创建会话对象时出现异常。

org.hibernate.MappingException:无法确定类型:com.vrde.daems.bean.GroupLevelBean,表:tbl_ParameterGroups,列:[org.hibernate.mapping.Column(level)]

谁能告诉我有什么问题?

4

1 回答 1

6

因为您在上面放置了@Idjava@GeneratedValue持久性注释:

@Id
@GeneratedValue
private int ParameterGroupId;

在同一时间:

@Id
@GeneratedValue
public int getParameterGroupId() {
    return ParameterGroupId;
}

只需将注释放在上面就足够了private int ParameterGroupId;

于 2012-11-30T16:37:53.460 回答