-->
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: Returning values of collection
PostPosted: Wed Apr 04, 2007 6:52 am 
Beginner
Beginner

Joined: Mon Nov 13, 2006 8:22 am
Posts: 28
hi,

I have a table IO which contains a Set <String> of labels:
Code:
<hibernate-mapping>
    <class name="IO" table="IO">
    ...
   
    <set name="labels" table="LABELS" lazy="false">
   <key column="IO_ID" />
   <element type="java.lang.String" column="LABEL" />
    </set>
    ...


So, you will have a table LABELS like this:

IO_ID LABEL
1 Car
2 Food
3 Car
...

Now, I want it to return a (distinct) list of all LABEL in the table LABELS.
I've tried about anything but I can't get this (you would think so) simple function to work.

Hopefully, someone can tell what stupid mistake(s) I've made?

tx a lot,
Stijn


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 7:11 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
You have to define label as an entity if you want to do some queries on labels like "from Label".
As label is an element in your case you cannot access it directly in your hql queries

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 7:48 am 
Beginner
Beginner

Joined: Mon Nov 13, 2006 8:22 am
Posts: 28
tx,

I've tried that and it works; however, I'm not thrilled by the fact that I have to create a class Label with simply a property Label but I can live with it.

Could you help me out with 2 related questions?

1. return getHibernateTemplate().find("from Label");

Do you also know how I can get a distinct list of labels?

2. Actualy I have a joined-subclass-structure going on:

IO is the super-class of Cost & Incoms, so I also have 3 tables (IO, Cost & Incoms). Labels are kept in IO. How can I fetch a list of labels only containing the labels referenced by Cost?

I've tried:

"from Label where l.IO_ID in (select IO_ID from Cost)"

"from Label l join Cost c "

"from Label l join Cost c where l.IO_ID = c.IO_ID"

All of these give exceptions.

tx!
[/img]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 04, 2007 9:34 am 
Beginner
Beginner

Joined: Mon Nov 13, 2006 8:22 am
Posts: 28
never mind, I think I found the solution(s):

"select distinct l.label from Cost c join c.labels l"


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.