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: How to update/delete records thru HQL
PostPosted: Mon Dec 11, 2006 1:10 am 
Beginner
Beginner

Joined: Mon Oct 30, 2006 12:46 am
Posts: 26
Hi ,


Till now i have used HQL for creating and retrieving the data from database. It worked successfully. But i yday i tried for updating the record by using below sample code.

-------------------------------------------------------------------------

public int updateCommand(long commandId,Component component)
{
log.debug("Inside:updateCommand");

try
{
Session session = HibernateSessionFactory.getSession();
Transaction tx = session.beginTransaction();
String hqlUpdate="update Command comm set comm.component="+component+" where comm.commandId ="+commandId;
Query updateQuery=session.createQuery(hqlUpdate);
int update=updateQuery.executeUpdate();
tx.commit();
session.close();
log.debug("Successfully updated");
return update;
}catch (RuntimeException re) {
log.error("Updation failed ");
throw re;
}
}



--------------------------------------------------------------------------------
Here i am getitng error saying that executeUpdate not there at Query.

Could anyone help me how to update/delete records thru HQL effectivily.

Eagerly waiting for youe replys.

Thanks
Praveen.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 1:50 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
HQL is only designed to query the database. If you want to execute INSERT or UPDATE statements you have to use ADO.NET.

Regards
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 11, 2006 4:18 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Try posting your question in the Java forum, this is the forum for NHibernate on .NET.


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.