-->
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: execute straight SQL?
PostPosted: Tue Oct 07, 2003 5:09 pm 
Newbie

Joined: Tue Oct 07, 2003 4:17 pm
Posts: 9
Can someone point me to a Hibernate API that would let me execute straight SQL, i.e. not generated by Hibernate. And I would want to be able to iterate a resultset to build my own objects.... is this supported somehow?
Thx


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 5:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
java.sql.Connection myJdbcConnection = myHibernateSession.connection();
...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 5:26 pm 
Beginner
Beginner

Joined: Tue Oct 07, 2003 4:41 am
Posts: 21
Bit of a newbie myself but I think what you may be looking for is

SQL Queries (Chapter 14 of the 2.1b4 ref doc)

Code:
Query sqlQuery = sess.createSQLQuery("select {xc.*} from XCAT {xc}", "xc", Cat.class);
sqlQuery.setMaxResults(50);
List cats = sqlQuery.list();



is the example code taken from the top of the chapter

John


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 2:01 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Build your own objects ? may I ask why ? And do you know the implications for it ?
(I know a couple of reasons - but I would like to hear yours ;)

Options you got:
1. session.connection().putYourFavoriteJDBCStuffHere()
2. session.createSQLQuery();
3. HQL new() syntax ...like "select new PersonDTO(p.name, p.address) from Person p
4. HQL report queries like "select p.name, p.address from Person" ...


That should give you data in a tabular form from which you can create ya' own objects

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 08, 2003 6:16 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
5. Create a custom ClassPersister :)


Top
 Profile  
 
 Post subject: the motivation...
PostPosted: Wed Oct 08, 2003 11:07 am 
Newbie

Joined: Tue Oct 07, 2003 4:17 pm
Posts: 9
is basically legacy driven - a pre-determined data model, lots of existing SQL and other non-Java modules that need to continue to work.

Thanks much for the pointers.


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.