1
我想创建一个2对象(使用Java)之间的一对多映射。我可以将对象保存在数据库中,但不能保存它们之间的关系。我有一个名为“AuthorizationPrincipal”类,它包含一系列“特权”的Hibernate hbm多对多映射
<?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>
我想出了通过一些教程和示例下面的“设置”标签,但它还是赢了不保存在数据库中。
我想我可能已经犯了一个错误。我可能需要多对多而不是一对多。对象“AuthorizationPrincipal”包含一组“特权”对象。而且“Privilege”对象的实例可以包含在多个“AuthorizationPrincipal”对象中。防爆。 AP1可以包含priv1和priv2,然后AP2可以包含priv2和priv3。 – szrrizvi
在新的编辑中的解释@Zain Rizvi – richarbernal
谢谢,我解决了问题。这实际上是交易管理者的一个问题。 – szrrizvi