Hi,
The tutorial was good as i am a beginner with Hibernate. I tried the delete query example and i am not getting the expected output. The output comes as insurance has not been mapped. In the program too, there is no object formation of insurance table. Can you please explain me how this process works..
Thanks,
Ramya.
Hi,
The tutorial was good as i am a beginner with Hibernate. I tried the delete query example and i am not getting the expected output. The output comes as insurance has not been mapped. In the program too, there is no object formation of insurance table. Can you please explain me how this process works..
Thanks,
Ramya.
Instead of using the query we can use the delete method in org.hibernate.Session
In the above example, to delete the row in insurance with id=2, we may use the following:
Transaction tran = sess.beginTransaction();
Insurance insurance = (Insurance)sess.get(Insurance.class, 2);
sess.delete(insurance);
tran.commit();
in this delete class, int row = query.executeUpdate();
line was showing the error like "The method executeUpdate() is undefined for the type Query" can you clear my query.
pls change the all hibernate stating code because they all are worked properly but they dont take effect in database
so again make some changes here
one more thing is for note:
<!--delete from Insurance insurance where id = 2"; -->
here First "Insurance" is use the name of your "bean name"
Other is "insurance" is use the name of your database "table name"
<!-- changed code -->
public class FirstExample extends Contact{
public static void main(String[] args) {
Session session = null;
Transaction transaction = null ;
try{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session = sessionFactory.openSession();
transaction = session.beginTransaction();
transaction.begin();
String hql = "delete from Contact contact where id = 7";
Query query = session.createQuery(hql);
int row = query.executeUpdate();
if (row == 0){
System.out.println("Doesn't deleted any row!");
}
else{
System.out.println("Deleted Row: " + row);
}
transaction.commit();
session.flush();
session.close();
}
catch(Exception e){
System.out.println("error in first"+e.getMessage());
}
}
}
your examples has errors or some lines of code are not present for a good execution for example do not has commit and transaction definition in several of them. The above example give me exception = null. Please revise the examples and your correct execution. Thanks
Hello Sir,
It is using SQL query to delete record. It is not the hibernate way to delete record. As SQL query would make it database dependent. Please update the code.
DATABASE CreationMukesh August 28, 2011 at 9:42 PM
Thanks for the code but you have not given how to design the database accordingly which may be difficult for beginner.
Regd Hibernate Delete Query ExampleRamya September 19, 2011 at 10:41 PM
Hi, The tutorial was good as i am a beginner with Hibernate. I tried the delete query example and i am not getting the expected output. The output comes as insurance has not been mapped. In the program too, there is no object formation of insurance table. Can you please explain me how this process works.. Thanks, Ramya.
Regd Hibernate Delete Query ExampleRamya September 19, 2011 at 10:42 PM
Hi, The tutorial was good as i am a beginner with Hibernate. I tried the delete query example and i am not getting the expected output. The output comes as insurance has not been mapped. In the program too, there is no object formation of insurance table. Can you please explain me how this process works.. Thanks, Ramya.
Delete one row using hibernate without queryRUSHO SHAW December 1, 2011 at 4:26 PM
Instead of using the query we can use the delete method in org.hibernate.Session In the above example, to delete the row in insurance with id=2, we may use the following: Transaction tran = sess.beginTransaction(); Insurance insurance = (Insurance)sess.get(Insurance.class, 2); sess.delete(insurance); tran.commit();
WNoghavkgDHibuRkBrandice December 13, 2011 at 9:49 PM
This infroatmion is off the hizool!
errorkumar March 21, 2013 at 3:49 PM
in this delete class, int row = query.executeUpdate(); line was showing the error like "The method executeUpdate() is undefined for the type Query" can you clear my query.
Modification to codehjc January 13, 2012 at 3:22 AM
Downloaded latest hibernate.jar from sourceforge.net public static void main(String[] args) { // TODO Auto-generated method stub Session sess = null; try { SessionFactory fact = new Configuration().configure().buildSessionFactory(); sess = fact.openSession(); Transaction transaction = sess.beginTransaction(); String hql = "delete from roseindia.tutorial.hibernate.Insurance where ID = 3"; Query query = sess.createQuery(hql); int row = query.executeUpdate(); transaction.commit(); if (row == 0){ System.out.println("Doesn't deleted any row!"); } else{ System.out.println("Deleted Row: " + row); } sess.flush(); sess.close(); } catch(Exception e){ System.out.println(e.getMessage()); } }
errorjubinpatel March 1, 2012 at 1:24 PM
pls change the all hibernate stating code because they all are worked properly but they dont take effect in database so again make some changes here one more thing is for note: <!--delete from Insurance insurance where id = 2"; --> here First "Insurance" is use the name of your "bean name" Other is "insurance" is use the name of your database "table name" <!-- changed code --> public class FirstExample extends Contact{ public static void main(String[] args) { Session session = null; Transaction transaction = null ; try{ SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory(); session = sessionFactory.openSession(); transaction = session.beginTransaction(); transaction.begin(); String hql = "delete from Contact contact where id = 7"; Query query = session.createQuery(hql); int row = query.executeUpdate(); if (row == 0){ System.out.println("Doesn't deleted any row!"); } else{ System.out.println("Deleted Row: " + row); } transaction.commit(); session.flush(); session.close(); } catch(Exception e){ System.out.println("error in first"+e.getMessage()); } } }
qualityJose -Galeano August 27, 2012 at 9:51 PM
your examples has errors or some lines of code are not present for a good execution for example do not has commit and transaction definition in several of them. The above example give me exception = null. Please revise the examples and your correct execution. Thanks
It is not using hibernate method to delete recordManoj December 18, 2012 at 4:15 PM
Hello Sir, It is using SQL query to delete record. It is not the hibernate way to delete record. As SQL query would make it database dependent. Please update the code.
hai i like your website.....the legend April 9, 2013 at 7:15 PM
it's very useful to us for web development....
Post your Comment