我正在尝试在 2 个对象之间创建一对多映射(使用 Java)。我能够将对象保存在数据库中,但不能保存它们的关系。我有一个名为“AuthorizationPrincipal”的类,它包含一组“权限”
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package="org.openmrs">
<class name="AuthorizationPrincipal" table="authorization_principal" lazy="false">
<id
name="authorizationPrincipalId"
type="int"
column="authorization_principal_id"
unsaved-value="0"
>
<generator class="native" />
</id>
<discriminator column="authorization_principal_id" insert="false" />
<property name="name" type="java.lang.String" column="name" unique="true"
length="38"/>
<many-to-one
name="creator"
class="org.openmrs.User"
not-null="true"
/>
<property
name="uuid"
type="java.lang.String"
column="uuid"
length="38"
unique="true"
/>
<property
name="dateCreated"
type="java.util.Date"
column="date_created"
not-null="true"
length="19"
/>
<property
name="policy"
type="java.lang.String"
column="policy"
not-null="true"
length="255"
/>
<!-- Associations -->
<set name="privileges" inverse="true" cascade=""
table="authorization_principal_privilege" >
<key column="authorization_principal_id" not-null="true"/>
<many-to-many class="Privilege">
<column name="privilege" not-null="true" />
</many-to-many>
</set>
</class>
我通过一些教程和示例提出了“set”标签,但它仍然不会保存在数据库中。