-->
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: Retrieving top 10 entity elements without bidir. relation
PostPosted: Tue Mar 04, 2008 2:39 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 4:00 am
Posts: 41
Hello everybody!

I'm stuck with a special requirement to a query.

* I have an entity whose properties can be changed.
* Whenever I save, I create a log entry in another table.
* Every entity has a collection of these log elements.
* The collection must only contain the 10 latest entries, b/c otherwhise it would take a very long time to fetch all history elements
* The Log entity must not have a property of the entity that it logs.

How can I retrieve the 10 latest history elements? I need something like:

"select top 10 elements(e.logentries) from entity as e where e.Id = ? order by e.logentries.date"

... which obviously won't work ;-)

Does anybody has an idea how to solve this problem?

thx in advance & kind regards


Top
 Profile  
 
 Post subject: Query setMaxResults(int maxResults)
PostPosted: Tue Mar 04, 2008 6:52 am 
Newbie

Joined: Mon Jan 02, 2006 6:12 am
Posts: 6
Hi, are you looking for Query.setMaxResults(int maxResults)?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 04, 2008 7:33 am 
Beginner
Beginner

Joined: Wed Jan 16, 2008 4:00 am
Posts: 41
actually i was looking for this one:

int maxResults = this.HibernateTemplate.MaxResults;
this.HibernateTemplate.MaxResults = MAX_HISTORY_ELEMENTS;
IList<IHistory> history = HibernateTemplate.Find<IHistory>
("select c from Entity as t join t.Changes as c inner join fetch c.User where t.Id = ? "
+"order by c.Date desc", _typeId);
this.HibernateTemplate.MaxResults = maxResults;


I kinda missinterpreted the "elements(...)" thing


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.