Hi, I m using Hibernate 3 + javadb
my table is like:
CREATE table APP.BIDS ( BID_ID INTEGER NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), BIDDER_ID INTEGER NOT NULL , BID_AMOUNT INTEGER NOT NULL , ITEM_ID INTEGER NOT NULL )
I want to delete a row from table . My code is :
try{
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
org.hibernate.Transaction tx = session.beginTransaction();
String query1 = "delete from APP.BIDS where BID_ID = 16";
Query query = session.createQuery(query1);
int row = query.executeUpate();
if(row==0)
logger.info("Doesn't delete row. Record not found .");
else
logger.info("Records deleted :"+row);
tx.commit();
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}finally{
session.close();
}
**But it is not working.. Eroor is like :**
2859 [main] DEBUG org.hibernate.impl.SessionImpl - executeUpdate: delete from APP.BIDS where BID_ID = 14
2859 [main] DEBUG org.hibernate.engine.QueryParameters - named parameters: {}
2922 [main] DEBUG org.hibernate.hql.ast.QueryTranslatorImpl - parse() - HQL: delete from APP.BIDS where BID_ID = 14
java.lang.NullPointerException at org.hibernate.hql.antlr.HqlSqlBaseWalker.path(HqlSqlBaseWalker.java:2193)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2281) at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2232) at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:498) at org.hibernate.hql.antlr.HqlSqlBaseWalker.deleteStatement(HqlSqlBaseWalker.java:276) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:156)
2938 [main] DEBUG org.hibernate.hql.AST - --- HQL AST ---
-[DELETE] CommonAST: 'delete'
+-[FROM] CommonAST: 'implied-from-so-i-can-use-the-fromClause-rule-during-analysis-phase'
| \-[DOT] CommonAST: '.'
\-[WHERE] CommonAST: 'where'
\-[EQ] CommonAST: '='
+-[IDENT] CommonAST: 'BID_ID'
\-[NUM_INT] CommonAST: '14'
2938 [main] DEBUG hql.parser - throwQueryException() : no errors
2984 [main] ERROR hql.parser - * ERROR: <AST>:0:0: unexpected end of subtree
2984 [main] DEBUG hql.parser - <AST>:0:0: unexpected end of subtree
<AST>:0:0: unexpected end of subtree at org.hibernate.hql.antlr.HqlSqlBaseWalker.path(HqlSqlBaseWalker.java:2201) at org.hibernate.hql.antlr.HqlSqlBaseWalker.path(HqlSqlBaseWalker.java:2180) at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2281) at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2232) at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:498) at org.hibernate.hql.antlr.HqlSqlBaseWalker.deleteStatement(HqlSqlBaseWalker.java:276) at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:156) 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:414) at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:814) at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:801) at org.hibernate.impl.QueryImpl.executeUpate(QueryImpl.java:89) at com.ex.SeventhExample.main(SeventhExample.java:43)
Please visit the following links:
private void Delete() { try { DefaultTableModel tableModel1 = (DefaultTableModel) jTable1.getModel(); Session session = HibernateUtil.getSessionFactory().openSession(); EPatientfees patient_fees = new EPatientfees(); session.beginTransaction(); String patientfees_id=jTable1.getValueAt(jTable1.getSelectedRow(),4).toString(); Query query = session.createSQLQuery("delete from epatientfees where epatientfeesid="+patientfeesid+""); int CheckUpdate = query.executeUpdate();
if (CheckUpdate == 0) System.out.println("Doesn't deleted any row!");
else
session.getTransaction().commit();
tableModel1.getDataVector().removeAllElements();
refreshtable();
}
catch(Exception e) { System.out.println(e.getMessage()); }
}