Hibernate deletequery java.lang.IndexOutOfBoundsException:Index: 0, Size:0

Hi

I am using the below query to delete a single record.But it is throwing Indexoutof bounds exception.

Below is the code

public class TestDelete {
public static void main(String[] args) {
Session session = null;
Query qry = null;
int row = 0;
SessionFactory sessionFactory = new Configuration().configure()
.buildSessionFactory();
session = sessionFactory.openSession();
Transaction Tr_ins = session.beginTransaction();
String hql = "";
try {
hql = "delete from BT_TEMPORARYTABLE where id = 17";
qry = session.createQuery(hql);
try {

row = qry.executeUpdate();
} catch (Exception e) {
e.printStackTrace();
}
Tr_ins.commit();
if (row == 0) {
System.out.println("--ROW NOT DELETED-");
} else {
System.out.println("-ROW DELETED--");
}

} catch (Exception e) {
System.out.println(e.getMessage());
} finally {
session.flush();
session.close();
}
}
}

When I execute the above program it is giving the below exception

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.RangeCheck(ArrayList.java:507)
at java.util.ArrayList.get(ArrayList.java:324)
at org.hibernate.hql.ast.HqlSqlWalker.postProcessDelete(HqlSqlWalker.java:418)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:175)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:427)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:865)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:89)
at firstpackage.TestDelete.main(TestDelete.java:29)
-


ROW NOT DELETED---

Any one help is appreciated.
Thanks

Please sign in to leave a comment.