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
|