ids for this class must be manually assigned before calling save() composite-id

hibernate  composite-id 存储的售后一定要指明ID



例如 

[code="xml"]

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
    Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
    <class name="com.model.entity.AcctUserRole" table="ACCT_USER_ROLE" schema="MODEL">
        <composite-id name="id" class="com.model.entity.AcctUserRoleId">
            <key-many-to-one name="acctUser" class="com.model.entity.AcctUser">
                <column name="USER_ID" precision="9" scale="0" />
            </key-many-to-one>
            <key-many-to-one name="acctRole" class="com.model.entity.AcctRole">
                <column name="ROLE_ID" precision="9" scale="0" />
            </key-many-to-one>
        </composite-id>
        <many-to-one name="acctUser" class="com.model.entity.AcctUser" update="false" insert="false" fetch="select">
            <column name="USER_ID" precision="9" scale="0" not-null="true" />
        </many-to-one>
        <many-to-one name="acctRole" class="com.model.entity.AcctRole" update="false" insert="false" fetch="select">
            <column name="ROLE_ID" precision="9" scale="0" not-null="true" />
        </many-to-one>
    </class>
</hibernate-mapping>




AcctUserRole 需要保存的时候

调用如下

AcctUserRole aur = new AcctUserRole();
AcctUserRoleId auri = new AcctUserRoleId();
AcctRole ar = new AcctRole();
ar.setId(id_);
auri.setAcctRole(ar);
auri.setAcctUser(entity);
aur.setId(auri);
acctUserRoleDAO.save(aur);

你可能感兴趣的:(Hibernate,xml,.net,MyEclipse)