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: How to query for properties of composite-elements?
PostPosted: Mon Feb 07, 2005 1:51 pm 
Newbie

Joined: Sun Jan 30, 2005 12:22 pm
Posts: 5
Hibernate version:
2.1.7c

Mapping documents:

<hibernate-mapping>
<class
name="persistence.Channel"
table="TBL_CHANNEL"
dynamic-update="false"
dynamic-insert="false"
>

<id
name="uid"
column="UID"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="hilo">
</generator>
</id>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="NAME"
/>

<property
name="description"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="DESCRIPTION"
/>

<set
name="measurements"
table="TBL_MEASUREMENT"
lazy="true"
inverse="false"
cascade="none"
sort="unsorted"
>

<key
column="FK_CHANNEL"
>
</key>

<composite-element
class="persistence.Measurement"
>
<property
name="secTime"
type="java.lang.Long"
update="true"
insert="true"
access="property"
column="SEC_TIME"
/>

<property
name="meteredValue"
type="java.lang.Double"
update="true"
insert="true"
access="property"
column="METERED_VALUE"
/>

<property
name="status"
type="java.lang.Long"
update="true"
insert="true"
access="property"
column="STATUS"
/>

</composite-element>

</set>

</class>

</hibernate-mapping>

Name and version of the database you are using:

It's the same with hsqldb or Oracle 9.2i


Hi,

I find no way (and no examples) how to query collections of composite-elements for an element property.
I have a class Channel that has a collection of values (set) of class Measurement. A measurement has a timestamp, a value and a status.
Now I have to find a query which selects the measurements within a certain time range. I can select the whole collection with the elements() function:
Collection measurements = sess.find("select elements(channel.measurements) from persistence.Channel as channel where channel.name = 'Channel 1'");

But as soon as I try to add properties of the Measurement class to the where clause I get errors.
I tried a lot of different join syntaxes with different errors but nothing that works.
So I have to assume that I am just too stupid to find the solution. :-( I have no problem with collections of entities so (e.g. with Session.filter()), but with collections of values I am totally lost.
So please can someone show me the way?


Thanx

Volker


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 4:54 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
select m from persistence.Channel as channel join channel.measurements m where channel.name = 'Channel 1' and m.max > :max

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 5:18 pm 
Newbie

Joined: Sun Jan 30, 2005 12:22 pm
Posts: 5
Thanx for the reply Emmanuel,

that was one of my earlier attempts.

BUT:
I assume that with m.max you mean m.THE_COMPOSITE_ELEMENT_PROPERTY

So if I have the following query:

select m from persistence.Channel as channel join channel.measurements m where channel.name = 'Channel 1' and m.secTime>50

(secTime is the requested property. It's the seconds since 1.1.1970)


I get the following stack trace:

net.sf.hibernate.QueryException: could not resolve property: id of: persistence.Measurement [select m from persistence.Channel as channel join channel.measurements m where channel.name = 'Channel 1' and m.secTime>50]
at net.sf.hibernate.persister.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:38)
at net.sf.hibernate.collection.AbstractCollectionPersister.toType(AbstractCollectionPersister.java:663)
at net.sf.hibernate.hql.PathExpressionParser.getPropertyType(PathExpressionParser.java:249)
at net.sf.hibernate.hql.PathExpressionParser.end(PathExpressionParser.java:288)
at net.sf.hibernate.hql.SelectPathExpressionParser.end(SelectPathExpressionParser.java:14)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:170)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114)
at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:143)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:149)
at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:138)
at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:293)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1561)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1532)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1520)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)


Hibernate could not resolve property: id of: persistence.Measurement because it is a collection of values which has NO id property.
It works beautifully if I have a collection of entities (which has of course an id). Everything I tried with collection of entities worked just like the documentation says and as soon as I try to make it work with a collection of values I get errors like the above. :-(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 5:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Queries cannt return a composite element instance. It is the select clause which is the problem. This is a limitation I really want to fix in the new parser.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 5:44 pm 
Newbie

Joined: Sun Jan 30, 2005 12:22 pm
Posts: 5
Thanx Gavin,

so is there ANY way to retrieve a subset of a large collection of values ?
In my case I have one channel and maybe a measurement every minute. So the collection grows really big, but in most cases you only need the values of the last day or hour.
From the relational model it is a collection of values in the best sense. The measurements have no lifecycle of their own. They are just values of the channel. But if there is really NO way, I have to think again.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 5:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Make Measurement an entity.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 7:10 pm 
Newbie

Joined: Sun Jan 30, 2005 12:22 pm
Posts: 5
Ok thanx,

then I have to look how I do that without spending additional columns for ids, because this table will go into the terabyte ranges in the real world and additional columns would deadly.

Thanx for your help Gavin and Emmanuel

Cu

Volker


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 15, 2005 2:15 am 
Beginner
Beginner

Joined: Mon Sep 27, 2004 3:48 am
Posts: 23
Hi all,

In this case, if I know Measurement.status value, how to query the Channel by Criteria but not HQL?

Criteria criteria = session.createCriteria(Channel.class);
...
...
...


Top
 Profile  
 
 Post subject: Returning a composite element instance fixed yet?
PostPosted: Wed Apr 18, 2007 4:03 pm 
Newbie

Joined: Sun Apr 10, 2005 1:35 pm
Posts: 3
Gavin: "Queries cannt return a composite element instance. It is the select clause which is the problem. This is a limitation I really want to fix in the new parser."

I'm using Hibernate 3.2 and running into this issue. Has this been issue of allowing the return of a composite element instance been fixed yet?

Mark


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.