sca*_*anE 2 java struts hibernate struts2
我有2个Entity类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;
}
}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
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;
Run Code Online (Sandbox Code Playgroud)
并在同一时间上面:
@Id
@GeneratedValue
public int getParameterGroupId() {
return ParameterGroupId;
}
Run Code Online (Sandbox Code Playgroud)
它足以将注释放在上面 private int ParameterGroupId;
归档时间: |
|
查看次数: |
102 次 |
最近记录: |