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: getting resultset
PostPosted: Fri Dec 03, 2004 4:53 pm 
Beginner
Beginner

Joined: Thu Jul 29, 2004 7:14 pm
Posts: 41
Hibernate version: 2.17

I am trying to introduce the Hibernate with our existing system. One of the existing components needs data in a result set while the data i am getting from Hibernate is object. My question is how can I do it ? Even if I write a SQL query and call it through session.createSQLQuery() method, I got objects as the Hibernate book says on Page 242 :

there is direct SQL with automatic mapping of result sets to objects.

I want it the other way around. Any input?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 04, 2004 6:50 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
The main purpose of useing an ORM tool is, that you don't have to deal with things like resultsets. If your application deals with resultsets and (prepared)statements already you're maybe better of looking for a framework which makes the JDBC handling easier. (Have a look at Spring).

If you need the resultset only in some rare cases you can always get the current connection (Session.connection()) and do all the JDBC sutff yourself. If you do update/delete/insert calls to the db be carfull, since hibernate doesn't know anything about your operations and may get out of sinc with the db.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 1:16 pm 
Beginner
Beginner

Joined: Thu Jul 29, 2004 7:14 pm
Posts: 41
You are right about resultset. But we cannot discard the old code right away. We will be fixing the old code gradually. But for now we have to find workaround. Fortunately we need resultset like that in rare cases.

To pass resultset we use a RowSetAdaptor class :

import java.io.Serializable;
import java.sql.ResultSet;
import com.sun.rowset.CachedRowSetImpl;

public class RowSetAdaptor implements Serializable {
private CachedRowSetImpl rowset;
public RowSetAdaptor() {
try {
rowset = new CachedRowSetImpl();
}
catch( Exception e ){
System.out.println( "RowSetAdaptor: constructor --> " + e.getMessage() );
e.printStackTrace();
}
}

public void populate( ResultSet data ) {
try {
rowset.populate(data);
}
catch( Exception e ){
System.out.println( "RowSetAdaptor: populate --> " + e.getMessage() );
e.printStackTrace();
}
}
...
}

I was thinking about using ScrollableResults of Hibernate and translating it into RowSetAdaptor. Is it possible?

thanks


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.