您的位置:首页 > 移动开发

Hibernate_should be mapped with insert="false" update="false"的解决方法

2015-11-10 09:43 615 查看
今天在配置hibernate 单向多对一映射时出现了启动异常,第一句末尾出现了should be mapped with insert="false" update="false"提示

原因是存在账户和角色的多对一关系

在账户对应的实体类中添加了ROLE_ID属性,之后又配置了

导致ROLE_ID重复

解决方法:删除Account类中的ROLE_ID属性和对应get,set方法,在Account.hbm.xml中删除对应的property即可

以下为修改后的部分源码

ACCOUNT 类:

public class Account {

private Integer accountid;

private String accountname;

private String password;

private Integer aisuser;

private Role accrol;

public Integer getAccountid() {

return accountid;

}

public void setAccountid(Integer accountid) {

this.accountid = accountid;

}

public String getAccountname() {

return accountname;

}

public void setAccountname(String accountname) {

this.accountname = accountname;

}

public String getPassword() {

return password;

}

public void setPassword(String password) {

this.password = password;

}

public Integer getAisuser() {

return aisuser;

}

public void setAisuser(Integer aisuser) {

this.aisuser = aisuser;

}

public Role getAccrol() {

return accrol;

}

public void setAccrol(Role accrol) {

this.accrol = accrol;

}

}

ROLE类:

public class Role {

private Integer rid;

private String rname;

private Integer ruse;

private Set<Function> funcset;

public Integer getRid() {

return rid;

}

public void setRid(Integer rid) {

this.rid = rid;

}

public String getRname() {

return rname;

}

public void setRname(String rname) {

this.rname = rname;

}

public Integer getRuse() {

return ruse;

}

public void setRuse(Integer ruse) {

this.ruse = ruse;

}

public Set<Function> getFuncset() {

return funcset;

}

public void setFuncset(Set<Function> funcset) {

this.funcset = funcset;

}

}

ACCOUNT.HBM.XML:

<hibernate-mapping package="cn.edu.teachInNet.main.common.entity">

<class name="Account" table="account">

<id name="accountid" type="java.lang.Integer">

<column name="ACCOUNT_ID" />

<generator class="identity" />

</id>

<property name="accountname" type="java.lang.String">

<column name="ACCOUNT_NAME" />

</property>

<property name="password" type="java.lang.String">

<column name="PASSWORD" />

</property>

<property name="aisuser" type="java.lang.Integer">

<column name="ACCOUNT_ISUSER" />

</property>

<!-- 映射单向多对一关系,多个账户对应一个角色 -->

<many-to-one name="accrol" class="Role" column="ROLE_ID"></many-to-one>

</class>

</hibernate-mapping>

ROLE.HBM.XML:

<hibernate-mapping package="cn.edu.teachInNet.main.common.entity">

<class name="Role" table="role">

<id name="rid" type="java.lang.Integer">

<column name="ROLE_ID" />

<generator class="identity" />

</id>

<property name="rname" type="java.lang.String">

<column name="ROLE_NAME" />

</property>

<property name="ruse" type="java.lang.Integer">

<column name="ROLE_ISUSER" />

</property>

<!-- 映射单向多对多关系,角色和权限多对多 -->

<set name="funcset" table="rol_fun" cascade="save-update" >

<key>

<column name="ROLE_ID"></column>

</key>

<many-to-many class="Function" column="FUNCTION_ID"/>

</set>

</class>

</hibernate-mapping>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: