hibernate delete query :

Ads

 
 

Share on Google+Share on Google+

narendram
hibernate delete query :
2 Answer(s)      6 years and 2 months ago
Posted in : Hibernate

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)

Ads
View Answers

August 4, 2012 at 12:02 PM


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()); }

}


Ads









Related Tutorials/Questions & Answers:
Tutorials   
Java Spring Hibernate Struts Training Hibernate envers revtype values Hibernate envers audit example Hibernate envers example Hibernate envers revinfo table revinfo table sql Hibernate maven dependency example What is the difference between JPA and Hibernate? How to turn off hbm2ddl? Hibernate hbm2ddl.auto values Hibernate table not mapped error - solution Hibernate error class is not mapped Hibernate Envers custom revinfo table Hibernate Envers - REVINFO table doesn't exist How to enable second level cache in Hibernate 5? How to enable second level cache in Hibernate 5? java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based! org.hibernate.validator cannot be resolved error java.lang.ClassNotFoundException: org.hibernate.cache.TimestampsRegion java.lang.ClassNotFoundException: org.hibernate.cache.TimestampsRegion property hibernate.cache.region.factory_class is not given Hibernate example step by step in Eclipse with MySQL How to make Struts Hibernate and Spring Based Login/Registration Application? What is the use of Hibernate Native SQL? What is the use of Hibernate is used? How to integrate Struts and Hibernate in an application? How to create the program in Java for getting the forgotten Password Form? How to write create JPA Many-to-Many Relationship in Java? What is the DAO Layer in any application? What is Spring Struts Hibernate DAO Layer? How to write Example code for CRUD application in hibernate annotation? Where to update the Hibernate tools? Query conversion convert into hql how to convert sql into hql package org.hibernate.util does not exist C3P0 with Hibernate What do you understand by JPA? Hibernate Query Checker Jpa many to many relationship What do you understand by Hibernate in Java? What are criteria Queries in Hibernate? How to use Associations and Joins in Hibernate? Hibernate 4 Example with Eclipse How to learn Hibernate? What is Hibernate Framework? hibernate faq 15/03/14 hibernate 15/03/2014 Hibernate Criteria Wildcard how to add mulitiple projections this is a hibernate question

Ads

 
Advertisement null

Ads