-->
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.  [ 4 posts ] 
Author Message
 Post subject: [XDoclet] one-to-many
PostPosted: Sat Dec 11, 2004 5:03 pm 
Newbie

Joined: Tue Nov 30, 2004 5:07 am
Posts: 14
Currently I just try to understand how I declare an one-to-many association with XDoclet. I know the "@hibernate Tag Reference" http://xdoclet.sourceforge.net/xdoclet/tags/hibernate-tags.html , but unfortunately that is not enough for me.

From http://www.hibernate.org/hib_docs/online/workshop_toolset/java/src/org/hibernate/workshop/ I took the method getItems() from class User to understand how things work:

Code:
    /**
     * @hibernate.set
     *  inverse="true"
     *  lazy="true"
     *  cascade="save-update"
     * @hibernate.collection-key
     *  column="seller"
     * @hibernate.collection-one-to-many
     *  class="org.hibernate.workshop.toolset.Item"
     */
    public Set getItems() {
        return this.items;
    }


- With hibernate.set you specify that a set is used to manage a collection of items.
- With hibernate.collection-key... ???
- With hibernate.collection-one-to-many you specify the class that is saved within the collection (Items are saved in the collection in class User, because a User can have many Items: one-to-many)

It would be nice if somebody could put a comment on every single line of the example to explain how this works.

smo


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 11, 2004 6:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
The doclet tags map to hibernate mapping tags and attributes. If you understand how you can hand create a mapping hbm xml file then the doclet is much easier to understand. Having said that:

Quote:
- With hibernate.set you specify that a set is used to manage a collection of items.
- With hibernate.collection-key... ???
- With hibernate.collection-one-to-many you specify the class that is saved within the collection (Items are saved in the collection in class User, because a User can have many Items: one-to-many)


@hibernate.set - is the collection container to be used. In this case a HashSet. This matches the Java return type of the method that returns the collection.

@hibernate.collection-key - is the foreign key column in the child table.

@hibernate.collection-one-to-many class - It the domain object representing each individual record of the collection. Hibernate knows which table its referencing when it refers to the Item mapping document.

See the hibernate reference manual for the HBM xml markup.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 12, 2004 1:48 pm 
Newbie

Joined: Tue Nov 30, 2004 5:07 am
Posts: 14
Thanks for answering. I think your advice to first get the hbm-notation and then move on to XDoclet should work fine.

By the way I found a nice Hibernate-XDoclet-Tutorial:
http://www.downside.ch/hibernate/

I think it would be nice if someone could add a link to HibernateDocs-area..

smo


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 12, 2004 8:17 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I have added the reference to the Wiki.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.