-->
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.  [ 7 posts ] 
Author Message
 Post subject: select java objects with no-SQL variable
PostPosted: Tue Nov 22, 2005 3:02 am 
Newbie

Joined: Tue Apr 13, 2004 2:36 am
Posts: 5
Hello,

I need construct select, when return java objects with constructor, but in constructor I want put some no-SQL variable, for example I have ViewClass:

public class ViewClass {

private Long id;
private String name;
private Timestamp date;
boolean timeout;

public ViewClass (Long id, String name, Timestamp date, long timeout) {
this.id = id;
this.name=name;
this.date=date;
if (timeout>date.getTime()) this.timeout=true;
else this.timeout=false;
}

}

and want create select what:

select new ViewClass(tab.id, tab.name, tab.date, 123456789) from MyTable tab

I have problem with last constructor parameter, Hibernate not accept this select construction. Have someone idea for solution this problem?

M. Demian


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 5:59 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Since it is a constant, why push it into hql?
Simply set it on the java object.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 7:48 am 
Newbie

Joined: Tue Apr 13, 2004 2:36 am
Posts: 5
More correct, this is not constant, but variable what:

long time = <exp.>;

session.createQuery("select new ViewClass(tab.id, tab.name, tab.date, " + time + ") from MyTable tab");


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 7:52 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
The same stuff.

Code:
long time = ...
ViewClass vc = session.
vc.setTime(time);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 8:01 am 
Newbie

Joined: Tue Apr 13, 2004 2:36 am
Posts: 5
Yes, of course,

but this select not return only one object, but list of objects. I looking for better solution when evade requirement iterate this list and call setTime for all objects.

But if no exist other solution, I must accept iterating solution :-(


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 8:05 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Push this code into the ViewClass constructor.
Or implement your own interceptor.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 10:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
or just use hibernate 3.1 where that query will work.

_________________
Max
Don't forget to rate


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