-->
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: Using a dynamic HSQL query to load a class
PostPosted: Tue Sep 12, 2006 11:04 am 
Newbie

Joined: Mon Apr 18, 2005 1:10 pm
Posts: 4
Hibernate version:3.0

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="com.company.model.position">
<class name="CorporateAggregatedPosition">
<id name="id" type="long" />
<property name="name" length="100" type="string"></property>
<property name="gradeCode" type="string"></property>
<property name="delta" type="big_decimal"></property>
</class>
</hibernate-mapping>

Name and version of the database you are using:
Sybase 12.0

Is it possible to populate a class that is not directly mapped to any database object using a dynamic HSQL query. The query will be built based on user inputs and use the results to populate the class in the mapping file above. I have managed to run the HSQL query which returns a list of objects. I would like it to return a list of CorporateAggregatedPositions instead in order for it to be useful. I know it is possible to use loader and specify a named SQL query in the mapping file but this is not dynamic and is based on SQL.

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 12, 2006 1:18 pm 
Senior
Senior

Joined: Wed Aug 17, 2005 12:56 pm
Posts: 136
Location: Erie, PA (USA)
Look for "Dynamic Instanciation" in the manual.

Basically, the syntax is:
Code:
SELECT new ResultsBean(obj1.prop1, obj1.prop2, ...) FROM Object1 obj1


"ResultsBean" is just a java bean with the corresponding fields, accessors and constructor -- it does not need to "mapped" or referenced in the .cfg.xml.

Curtis ...

_________________
---- Don't forget to rate! ----


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 13, 2006 6:36 am 
Newbie

Joined: Mon Apr 18, 2005 1:10 pm
Posts: 4
Thanks for the response.

I was wandering is it also possible to return the row number in the result set somehow so that I could use it as an id in the class I am trying instantiate dynamically?

The reason being I will be performing a group by in the HSQL query.

Regards

Ketan


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.