繁体   English   中英

休眠映射异常

[英]Hibernate Mapping Exception

我有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)]

谁能告诉我这是什么问题?

因为您在上面放置了@Id@GeneratedValue Java持久性注释,所以:

@Id
@GeneratedValue
private int ParameterGroupId;

并在上述同一时间:

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

它足以将注释放在private int ParameterGroupId;之上private int ParameterGroupId;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM