-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem with delete sql
PostPosted: Wed Nov 15, 2006 4:46 am 
Newbie

Joined: Wed Nov 15, 2006 4:34 am
Posts: 1
Hi,
I need your help.
I am using HibernateDaoSupport.
so all the database related things i am doing using
getHibernateTemplate().
method.

Now i want to delete some rows from a table so instead of passing list of object i want to do it in a single query like this
My SQL fro delete:
Delete from Table_Name where Id =Some_value;

so can any body help me how can i perform this task by writting a single sql and executing it by getHibernateTemplate().
Please help me.
thanks in advance.[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 15, 2006 5:12 am 
Expert
Expert

Joined: Tue Dec 07, 2004 6:57 am
Posts: 285
Location: Nürnberg, Germany
http://www.hibernate.org/hib_docs/v3/re ... tch-direct

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();

String hqlDelete = "delete Customer c where c.name = :oldName";
int deletedEntities = s.createQuery( hqlDelete )
.setString( "oldName", oldName )
.executeUpdate();
tx.commit();
session.close();

I think that you can do HQL from HibernateTemplate as well. Actually I would not encourage the use of HibernateTemplate in an Hibernate 3.x environment.

_________________
Please don't forget to rate


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