-->
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.  [ 3 posts ] 
Author Message
 Post subject: Query where clause on attribute of a collection element
PostPosted: Fri Jan 09, 2004 5:51 pm 
Newbie

Joined: Fri Jan 09, 2004 5:41 pm
Posts: 14
Hello,
I have tried several different ways to do what seems to me to be very common without success. If this is an easy one that I'm just missing, maybe someone can point me in the right direction. Have read the manual.

I have a class which has a bidirectional one-to-many association to a collection of entities, as in the manual section 8.2. Here is some of my cfg file:

<class name="com.fujisawa.compintel.app.to.DrugTO" table="intel_drugs">
<id name="drugId" type="long">
<column name="drug_id" sql-type="int" not-null="true"/>
<generator class="native"/>
</id>
<set name="names" inverse="true" cascade="all-delete-orphan">
<key column="drug_id"/>
<one-to-many class="com.fujisawa.compintel.app.to.NameTO"/>
</set>
...


<class name="com.fujisawa.compintel.app.to.NameTO"
table="intel_drug_names"
dynamic-update="true">
<id name="drugNameId" type="long">
<column name="drug_name_id" sql-type="int" not-null="true"/>
<generator class="native"/>
</id>
<many-to-one name="parent" column="drug_id" not-null="true"/>
<property name="name">
<column name="drug_name" sql-type="varchar(100)" not-null="true"/>
</property>

So a drug has several names. All I want is a query that returns DrugTO's for drugs which have a name = to my search criteria. The query I tries that seems to me most correct from the docs is this:

select d from DrugTO as d left join d.names as name where name.name ='aspirin'

which seems to load my entire database. There are sever other collections of classes that belong to drug similar to name, but I need to get one working first.

Thanks for any suggestions.

-Scott


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 10, 2004 10:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Enable SQL logging and check what SQL hibernate generates


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 10, 2004 11:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
I notice that your collection is not marked lazy="true"


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