-->
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.  [ 6 posts ] 
Author Message
 Post subject: Employer/Employee example question
PostPosted: Mon Feb 02, 2004 4:31 pm 
Newbie

Joined: Wed Jan 14, 2004 3:56 pm
Posts: 7
Location: Ann Arbor, MI, USA
Looking at section 18.1 of the manual... Could someone please show what the mapping for the Employer and Employee objects might be if they both had a collection of Employment objects?

Thanks, Will


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 4:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well, there are really a lot of mapping examples out there, for example in the hibernate tutorial list http://www.hibernate.org/78.html#A3. I am really to lazy to do handholding for your case, perhaps somebody else is not ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 5:23 pm 
Newbie

Joined: Wed Jan 14, 2004 3:56 pm
Posts: 7
Location: Ann Arbor, MI, USA
Well, I actually have been working hard to understand the mappings on my own. What I haven't found is enough examples of bidirectional many-to-many mappings where the relationship is an entity class. The Employer/Employee example is perfect for this if an Employment collection is added to Employer and to Employee.

I have a similar question about the Custoomer/Order/Product example, if Product had a collection of LineItem objects (an odd example, but still...)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 7:00 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I'll drive you, but in exchange, you'll create a wiki page for that after testing it, good deal, no ? :)

Actually it's the same as if there were a simple one-to-many, many-to-one links.

Code:
<class name="Employer" table="employers">
        <id name="id">
            <generator class="sequence">
                <param name="sequence">employer_id_seq</param>
            </generator>
        </id>
        <property name="name"/>
        <set name="employments" lazy="true">
            <key>
                <column name="employer_id" not-null="true"/>
            </key>
            <one-to-many class="Employment"/>
        </set>
    </class>


Same for the other side.

For Customer/Order/Product, you can't do it using a composite-element, composite-element are only related to it's father. So you need to replace composite-element by an Entity.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 8:31 am 
Newbie

Joined: Wed Jan 14, 2004 3:56 pm
Posts: 7
Location: Ann Arbor, MI, USA
It's a deal, Emmanuel. I'll work with this today and write something up.
Thanks.

Will


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 8:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Don't hesitate to post again if you have problems, we are not that lazy after all :) You just get better results in general if you try to work yourself into it and just post if you run into problems.


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