-->
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: A novice question, listing my relations?
PostPosted: Fri Aug 04, 2006 7:49 pm 
Newbie

Joined: Sat Jun 24, 2006 6:26 pm
Posts: 10
Hello!

Wrote my first hibernateapplication taken from the reference-guide 'Introduction to Hibernate'. The relation described is many-to-many.
The tables are EVENTS,PERSON_EVENT and PERSON.
The examples gives you the idea on how to create an event, create a person and then link them together through PERSON_EVENT.

The example does not show you how to show the events for a particular person. The way to do this using ordinary SQL would be ( not using JOIN here).

'select E.Title ,P.firstname from EVENT E, PERSON_EVENT X ,PERSON P where E.event_id=X.event_id and X.person_id=P.person_id and p.person_id=7'

Giving me the title of the event and firstname for person_id=7.

What would be the best way to do this in Hibernate, following the example in chapter 1 ?

Best regards, i


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 05, 2006 4:32 pm 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
select ev from Event as ev, ev.persons as prs where prs.id = ?

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject: thanks amir
PostPosted: Sun Aug 06, 2006 4:22 am 
Newbie

Joined: Sat Jun 24, 2006 6:26 pm
Posts: 10
will check out your solution this evening,
and then do my homework on HSQL.

Thanks!

- i


Top
 Profile  
 
 Post subject: Pasha, Incorrect Suggestion ....
PostPosted: Sun Aug 06, 2006 2:17 pm 
Newbie

Joined: Sat Jun 24, 2006 6:26 pm
Posts: 10
Hello Pasha!

If you read the chapter 1 , http://www.hibernate.org/hib_docs/v3/re ... orial.html .

Then you can see that there is no 'persons' in the Class Event.

Please check the example in ch1. again.
The only mapping is the following:

Code:
<class name="events.Person" table="PERSON">
    <id name="id" column="PERSON_ID">
        <generator class="native"/>
    </id>
    <property name="age"/>
    <property name="firstname"/>
    <property name="lastname"/>

    <set name="events" table="PERSON_EVENT">
        <key column="PERSON_ID"/>
        <many-to-many column="EVENT_ID" class="events.Event"/>
    </set>

</class>


is your suggestion that I create a 'Set person' in the Event-Class and
change the mapping in event.hbm.xml.

Please ge back to me and explain.

regards, i


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.