-->
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.  [ 2 posts ] 
Author Message
 Post subject: Basic Query Question with multiple entities
PostPosted: Tue Mar 22, 2005 2:18 pm 
Beginner
Beginner

Joined: Fri Jun 04, 2004 12:50 pm
Posts: 32
I have a question which I think should be quite easy to answer. I have looked everywhere for an answer and cannot seem to be able to find it partly I am guessing because I do not know the best way to ask the question.

I have two entities, a family and a camper which families can have many of. I am quite capable of querying for all families where lastName = xxxx where it returns all families and associated campers. But, I am not quite sure how to query for all families where camper lastName = yyyy and it will return all families and associated campers.

Is there a single link that someone can point me to for an example of this?

Thanks

Tom

Hibernate version:
2.1.8. the version incorporated into JBoss 4.0

Mapping documents:

The two entities are: Family

<class name="com.camp.common.family.Family" table="tblFamily">

<id name="familyID" type="integer">
<column name="id_family" sql-type="integer" not-null="true"/>
<generator class="sequence">
<param name="sequence">tblfamily_id_family_seq</param>
</generator>
</id>

<property name="parentOneLastName">
<column name="p1_last_name" sql-type="char(64)" not-null="true"/>
</property>

<property name="parentOneFirstName">
<column name="p1_first_name" sql-type="char(64)" not-null="true"/>
</property>

<set name="campers" lazy="false" cascade="all-delete-orphan" inverse="true">
<key column="fk_id_family"/>
<one-to-many class="com.camp.common.camper.Camper"/>
</set>

</class>

and Camper

<class name="com.camp.common.camper.Camper" table="tblCamper">

<id name="camperID" type="integer">
<column name="id_camper" sql-type="integer" not-null="true"/>
<generator class="sequence">
<param name="sequence">tblcamper_id_camper_seq</param>
</generator>
</id>

<property name="lastName">
<column name="last" sql-type="char(32)" not-null="true"/>
</property>

<property name="firstName">
<column name="first" sql-type="char(32)" not-null="true"/>
</property>

<property name="gender">
<column name="gender" sql-type="boolean" not-null="false"/>
</property>

<many-to-one name="family" class="com.camp.common.family.Family" column="fk_id_family" not-null="true"/>

</class>

Code between sessionFactory.openSession() and session.close():
N/A
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
Postgres 7.4.1

The generated SQL (show_sql=true):
N/A

Debug level Hibernate log excerpt:
N/A


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 22, 2005 4:19 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
select from Family f join f.campers camper where camper.name = XXX

of

select camper.family from Camper camper where camper.name = XXX


Easy ;)

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


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