-->
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.  [ 9 posts ] 
Author Message
 Post subject: query for set of element types
PostPosted: Thu Apr 20, 2006 10:07 am 
Newbie

Joined: Thu Apr 20, 2006 9:58 am
Posts: 6
Hello,
I can't find how to build an hibernate query for a mapping like this in the docuementation:

<set name="names" table="person_names">
<key column="person_id"/>
<element column="person_name" type="string"/>
</set>


I need to know all the existing person_names( select person_name from person_names, of course), but usin hsql, that is , without tables.

getSession().createQuery("select names from person").list()

throws an error sayig names is not an entity, which is true, in case of a set of entities it works, but how should I do in case of value types(elemens)?
Many Thanks in advance
Igor


Top
 Profile  
 
 Post subject: Re: query for set of element types
PostPosted: Thu Apr 20, 2006 10:19 am 
Regular
Regular

Joined: Wed Feb 22, 2006 11:28 am
Posts: 65
Location: Santiago, Chile
[quote="igorarbizu"]Hello,
I can't find how to build an hibernate query for a mapping like this in the docuementation:

[b]<set name="names" table="person_names">
<key column="person_id"/>
<element column="person_name" type="string"/>
</set>[/b]

I need to know all the existing person_names( select person_name from person_names, of course), but usin hsql, that is , without tables.

[b]getSession().createQuery("select names from person").list()[/b]

throws an error sayig names is not an entity, which is true, in case of a set of entities it works, but how should I do in case of value types(elemens)?
Many Thanks in advance
Igor[/quote]

Hello Friend:

I guess that you can create a Criteria, and then iterate the result set of Person.

After this, you say: person.getNames(), it will return you a list, then you add this resultSet into a Collection.

That is I wanna do if i was you, i think that is very inefficent. Waiting for ths post of others friends.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 10:56 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Code:
String hql = "select distinct p.names from Person p";
getSession().createQuery(hql).list();


Top
 Profile  
 
 Post subject: it does not work with dynamic model
PostPosted: Thu Apr 20, 2006 11:15 am 
Newbie

Joined: Thu Apr 20, 2006 9:58 am
Posts: 6
No,

select p.names from person name

it causes the same error (not an entity),
I'm working with Dynamic models (hibernate 3) so there is not class Person (getName() etc..) but a map

select p["names"] from person p (???) doesn't work either

any idea?
Thanks
Igor


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 11:43 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
post the full mapping file please


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 11:50 am 
Newbie

Joined: Thu Apr 20, 2006 9:58 am
Posts: 6
this is all the mapping the question is aboutmapping

<class entity-name="person" table="av_person">
<id name="id" type="string" column="id" />
<set name="names" table="person_names">
<key column="person_id"/>
<element column="person_name" type="string"/>
</set>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 11:50 am 
Newbie

Joined: Thu Apr 20, 2006 9:58 am
Posts: 6
this is all the mapping the question is aboutmapping

<class entity-name="person" table="av_person">
<id name="id" type="string" column="id" />
<set name="names" table="person_names">
<key column="person_id"/>
<element column="person_name" type="string"/>
</set>
</class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 20, 2006 1:47 pm 
Newbie

Joined: Thu Apr 20, 2006 9:58 am
Posts: 6
So I assume this is not possible with dynamic entities? is it a bug??


Top
 Profile  
 
 Post subject: Try this
PostPosted: Wed Aug 09, 2006 4:38 pm 
Newbie

Joined: Wed Aug 09, 2006 4:28 pm
Posts: 1
I'm not sure if this fits your question but:

I have a User Object that has a set of roles, which are simply strings so the mapping looks like that:

Code:
<class name="User" table="user">
        <property name="name" />
   <set name="roles" table="role" cascade="all">
      <key column="user_id"/>
      <element type="string" column="role" />
   </set>
</class>


Now to get a list of all users with a specific role I do this:

Code:
session.createQuery("from User u join u.roles as role where role=:ROLE")
                               .setParameter("ROLE", "newslettersender")
                               .list();



Note the 'join u.roles as role', which does the trick.

I just would like to know if and how this can be made using Criteria ...

regards, ridcully


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