-->
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: Basic createSQLQuery question
PostPosted: Thu Jun 09, 2005 2:43 pm 
Beginner
Beginner

Joined: Thu Jun 09, 2005 2:33 pm
Posts: 30
If I have a simple delete statement, that doesn't map to a pojo, can I use createSQLQuery to execute it? Or, do I have to obtain a connection from the session?

ex. String sql = "delete * from employee where emplid= :emplid";

getSession().createSQLQuery(sql).setString("emplid",emplid);

Will createSQLQuery always execute the query?


Top
 Profile  
 
 Post subject: Re: Basic createSQLQuery question
PostPosted: Thu Jun 09, 2005 2:58 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
graeder wrote:
If I have a simple delete statement, that doesn't map to a pojo, can I use createSQLQuery to execute it? Or, do I have to obtain a connection from the session?

ex. String sql = "delete * from employee where emplid= :emplid";

getSession().createSQLQuery(sql).setString("emplid",emplid);

Will createSQLQuery always execute the query?


createSQLQuery doesn't execute the query. And the proper syntax would be "delete from employee where emplid = :emplid" ( No * )

Look at the bottom of page 132 in the 3.0.5 docs for an example using a pojo. I don't think you can use Hibernate when not using a mapped pojo.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:08 pm 
Beginner
Beginner

Joined: Thu Jun 09, 2005 2:33 pm
Posts: 30
If you're not using a mapped pojo, couldn't you just get the jdbc connection from the session and execute the query?

ex. java.sql.Connection connection = session.connection();


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:14 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
graeder wrote:
If you're not using a mapped pojo, couldn't you just get the jdbc connection from the session and execute the query?

ex. java.sql.Connection connection = session.connection();


Yes that will work.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:32 pm 
Beginner
Beginner

Joined: Thu Jun 09, 2005 2:33 pm
Posts: 30
But, if I was doing a select on a mapped pojo, createSQLQuery would be sufficient to execute the query?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 09, 2005 3:37 pm 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
graeder wrote:
But, if I was doing a select on a mapped pojo, createSQLQuery would be sufficient to execute the query?


Assuming your object is named Employee...

String hqlString = "delete Employee where emplid = :emplid"
int deleteCnt = session.createQuery(hqlString).executeUpdate();


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.