
package pkg2; import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; public class NewClass3 {
public static void main(String[] args) { // TODO Auto-generated method stub Session sess = null; try { SessionFactory fact = new Configuration().configure().buildSessionFactory(); sess = fact.openSession(); org.hibernate.Transaction tx = sess.beginTransaction(); String hql = "delete from Insurance insurance where id = 2"; Query query = sess.createQuery(hql); int row = query.executeUpdate(); if (row == 0){ System.out.println("Doesn't deleted any row!"); } else{ System.out.println("Deleted Row: " + row); } tx.commit(); sess.close(); } catch(Exception e){ System.out.println(e.getMessage()); } } }
this is the code m using . Error is -query must begin with SELECT or FROM: delete [delete from pkg2.Insurance insurance where id = 2]
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.