Hibernate version:
Hibernate 2.1.2, XDoclet 1.2.1
I am having a problem using XDoclet to map a composite-element properly. I am trying to create a many-to-many relationship with a collection of components (I need associative properties along with the relationship.)
In short, the problem is that the generated *.hbm.xml files have two many-to-one relationships in the composite-element instead of just one. I need to manually remove one to get my test working. I want to know if I am setting up my XDoclet tags correctly.
This is the way I have it set up now.
Classes: Account 1---* SpaceAccount *---1 Space
// Account.java
/**
* @hibernate.list
* table="SPACES_ACCOUNTS"
* cascade="save-update"
* lazy="true"
* @hibernate.collection-key
* column="ACCOUNT_FK"
* @hibernate.collection-index
* column="SPACE_INDEX"
* @hibernate.collection-composite-element
* class="SpaceAccount "
*/
public List getSpaceAccounts() {
return spaceAccounts;
}
// Space.java
/**
* @hibernate.list
* table="SPACES_ACCOUNTS"
* cascade="save-update"
* lazy="true"
* @hibernate.collection-key
* column="SPACE_FK"
* @hibernate.collection-index
* column="ACCT_INDEX"
* @hibernate.collection-composite-element
* class="SpaceAccount"
*
*/
public List getSpaceAccounts() {
return spaceAccounts;
}
// SpaceAccount.java
/**
* @hibernate.many-to-one
* cascade="save-update"
* column="ACCOUNT_FK"
*/
public Account getAccount() {
return account;
}
/**
* @hibernate.many-to-one
* cascade="save-update"
* column="SPACE_FK"
*/
public Space getSpace() {
return space;
}
The result of running the Xdoclet generator on these is two files, Account.hbm.xml and Space.hbml.xml they both have the list set up with two many-to-ones instead of one. Here is the .hbm for Space class:
<list
name="SpaceAccounts"
table="SPACES_ACCOUNTS"
lazy="true"
inverse="false"
cascade="save-update"
>
<key
column="SPACE_FK"
>
</key>
<index
column="ACCT_INDEX"
/>
<composite-element
class="SpaceAccount"
>
<many-to-one
name="account"
class="Account"
cascade="save-update"
outer-join="auto"
update="true"
insert="true"
access="property"
column="ACCOUNT_FK"
/>
<many-to-one
name="space"
class="Space"
cascade="save-update"
outer-join="auto"
update="true"
insert="true"
access="property"
column="SPACE_FK"
/>
<property
name="createdDate"
type="java.util.Date"
update="true"
insert="true"
access="property"
column="createdDate"
/>
</composite-element>
</list>
To get this to work correctly I need to remove the <many-to-one> for space.
If I do not do that I get this error when I run the test:
net.sf.hibernate.MappingException: Repeated column in mapping for collection: spaceAccounts column: ACCOUNT_FK
Am I mapping my classes correctly with XDoclet?
Any suggestions are appreciated.
Thanks,
-ev
|