-->
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.  [ 6 posts ] 
Author Message
 Post subject: Sql query’s that do not map to objects
PostPosted: Fri Aug 12, 2005 9:10 am 
Newbie

Joined: Fri Aug 12, 2005 9:04 am
Posts: 1
Is there a way to map an sql statement to a java class that doesn’t exist. The reason I would want to do such a thing is because the reporting portion of my application returns result sets that do not directly map to domain objects.

Here is a simplified example of what I would like to do.

Code:
<sql-query name="MyReportQuery">
<return class="MyHeterogeneousResults">
<return-property name="firstName" column="first_name"/>
<return-property name="lastName" column="last_name"/>           
</return>
SELECT first_name, last_name
FROM Simple_Table
</sql-query>


Is there anyway to do this sort of thing without creating a Java class that maps to the MyHeterogeneousResults reference. If this is possible it would be great because I wouldn’t have to create classes for every mix of data I need to return. I have some queries in my application that do not map nicely to objects however majority of my application utilizes hibernate, and I would like to keep with this framework for database interaction.

Thanks,

Keith


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 9:32 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
You can use the return-scalar element in you named query see section 17.3 of the doc for example
http://www.hibernate.org/hib_docs/v3/re ... medqueries

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


Top
 Profile  
 
 Post subject: Hibernate is probably not the right tool.
PostPosted: Fri Aug 12, 2005 9:35 am 
Beginner
Beginner

Joined: Wed Jan 19, 2005 6:07 am
Posts: 20
For this functionallity, Hibernate is probably not the righ tool.

Since you apparently want to retrieve different columns for each request, my suggestion would be to create a custom class that take a hash-map as parameter defining which columns to retrieve and what condition should be set for that column.

Then you could generate your own SQL-statement , execute it, and parse up the result anyway you want (Set of Object-arrays, vectors or any matrix you would feel comfortable reading from to present).

As notet at the last page in Hibernate In Action :
Quote:
Finally, use SQL, JDBC, and stored procedures for the 5 percent of use cases you
can’t implement with Hibernate, such as mass data manipulation or complex
reporting queries with vendor-specific SQL functions.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 12:00 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Please don't quote from Hibernate2 documentation when you talk about Hibernate3.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 5:52 pm 
Beginner
Beginner

Joined: Wed Jan 19, 2005 6:07 am
Posts: 20
christian wrote:
Please don't quote from Hibernate2 documentation when you talk about Hibernate3.


The quote was taken from Hibernate In Action, and it clearly states that most of it still is valid in Hibernate 3.

from the foreword :

Quote:
However, the information
in this book is valid for Hibernate3; in fact, we consider it to be an essential
reference even for the new version.


I also believe this quote is valid regardless of which persistence-system you use.

I don't think the scalar-value approach is good enough, if the case is that the queries is defined at run-time. Then the actual columns isn't decided when the mapping is written, thus we can't name thye columns in the mapping-file, but have to dynamically generate the sql according to the choises made by the user.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 12, 2005 6:06 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I'm the author of your quote and I tell you it is _NOT_ valid.


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