-->
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.  [ 1 post ] 
Author Message
 Post subject: xdoclet, one-to-many with attribute -Hibernate in Action ch6
PostPosted: Tue Apr 25, 2006 4:13 pm 
Newbie

Joined: Sat Jan 14, 2006 8:03 pm
Posts: 18
Hi.

I am trying to use xdoclet to create a one-to-many relationship with an attribute, just like in chapter 6 of Hibernate in Action (p. 229). I am using a composite element, an intermediary Java class. I have the following:

Module.java
long id
String description
List pieces

Piece.java
long id
String description

ModulePiece.java
Module module
Piece piece
int quantity

... so in the module_pieces table I will have a "quantity" for each module_piece. Anyway, that's the idea.

In the book it says to use the following mapping:

<set name="pieces" lazy="true" table="MODULE_PIECES">
-<key column="ID_MODULE"/>
-<composite-element class="ModulePiece">
--<parent name="module"/>
--<many-to-one name="piece"
---class="Piece"
---column="ID_PIECE"
---not-null="true"/>
--<property name="quantity" column="quantity" not-null="true"/>
-</composite-element>
</set>

Ok. But if I want to use xdoclet to generate this mapping, how would I do it? I've tried lots of variations on the following code just above the getPieces() method in Module.java, and I can't get it to work:

/**
* @hibernate.set cascade="all-delete-orphan" lazy="false"
* @hibernate.key column="id_module"
* @hibernate.collection-composite-element class="com.mycompany.model.ModulePiece"
* @hibernate.parent name="module"
* @hibernate.many-to-one column="id_piece" class="com.mycompany.model.Piece" not-null="true"
* @hibernate.property column="quantity" not-null="true"
*/

My specific questions are:

1. Is this the best/only way to do this? I guess it's the recommended way if Hibernate in Action says so ...
2. Where the heck do the "name" parameters come from for @hibernate.parent and @hibernate.property, considering these 2 tags don't *have* any parameters ...
3. Would I have to put any xdoclet tags in the ModulePiece class, or is it all done in Module?

Sorry to go on so long. It's a complicated problem. To me it seems like a pretty common thing to have to do, but for some reason I can't find much info about it ...

You'll be saving me a lot of grief if you can give me a tip ...

Thanks.
Bob


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

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.