-->
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.  [ 5 posts ] 
Author Message
 Post subject: Hibernate 2.x equivalent to Hinernate 3.x Method...
PostPosted: Fri Oct 07, 2005 3:38 pm 
Newbie

Joined: Fri Oct 07, 2005 3:10 pm
Posts: 3
... SQLQuery#addScalar(String,Type)

Hi,

I use a native sql query in Hibernate 2.x. The result of the following select:

select tmp.scalar, {businessobj.*}
from businessobject businessobj
...
join tmptable tmp on tmp.x = ...
...
where ...

should be a List<Object[]> with a Long reference in Object[0] and a BusinessObject reference in Object[1]. The select without the scalar is easy. But I dont know how I can select the scalar in Hibernate 2.x. Exist an equivalent method in Hibernate 2.x like the SQLQuery#addScalar(String,Type) of Hibernate 3?

In this special case tmp.scalar is an ID of antother BusinessType, so it's possible to join the mapped table of this type. Therefor I could invoke the
Session#createSQLQuery(String,String[],Class[]) method of Hibernate. But I would'nt realy do that, because I need only the ID and I think the selection of the complete BusinessObject produces some overhead.

Thanks & bye,
André


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 4:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
that is a new feature of H3

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 4:37 pm 
Newbie

Joined: Fri Oct 07, 2005 3:10 pm
Posts: 3
doesn't really exist an equivalent thing in H2? Sorry, but I can't believe it.
What is the typically approach in a case like this in H2? Without a migration to H3 ;)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 5:05 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
eh - session.connection() and do what you want or simply just use scalar HQL query instead.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 5:35 pm 
Newbie

Joined: Fri Oct 07, 2005 3:10 pm
Posts: 3
Mhmm... the using of HQL isn't possible, one reason is I join a temporary table in the statement which isn't mapped in Hibernate.

The manually mapping of each selected field by using of a jdbc connection and createStatement(...).execute() is not convenient, because it's a large business object.

Another idea is to map Long, Integer, etc in Objects which are mapped to Hibernate. Like this:

HbnMappedInteger
+setInteger(Integer)
+getInteger():Integer

so it's possible to use Session#createSQLQuery(String,String[],Class[]). If the object contains only one field, it's possible to write a select like this:

select temp.id as {hbn.integer}, {businessObj.*}
...

createSQLQuery(select,new String[]{"hbn","businessObj"},new Class[]{HbnMappedInteger.class,BusinessObj.class})

Could this work?


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