-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: XDoclet composite-element problem.
PostPosted: Mon Aug 30, 2004 4:40 pm 
Newbie

Joined: Fri Aug 27, 2004 10:33 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Try
PostPosted: Tue Aug 31, 2004 1:08 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Hi.

It doesn's seem right to use @hibernate.collection-composite-element.
I can't give you any other reason than the term "composite" implies a VERY tight coupling to the state of the parent object. The imagine that two instances which manages the state of their individual composite element should be able to bind to the same relational object... nah!

I have user @hibernate.collection-many-to-many with great success.

Or just make one of the objects you want to have a relation "own" a composite collection, and the tie the other object in a relational class by using one-to-many for that object.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.