Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Update Query in Hibernate (Please Help)

 
sagili mohan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want update data in particular table for particular column in the database with Hibernate.

Can any one provide Hibernate Query for this.

My object is : NoticeSummary (It is having the property fields like transactionStatus, referenceNumberCds etc.,)

Iam creating like this:

Session s = HibernateSession.currentSession();

Query q = s.createQuery("FROM NoticeSummary n SET n.transactionStatus
= ? WHERE n.referenceNumberCds = ?");

But it is giving exception like

Caused by: net.sf.hibernate.QueryException: unexpected token: SET [FROM com.nextel.ebn.common.to.NoticeSummary n SET n.transactionStatus = ? WHERE n.referenceNumberCds = ?]
at net.sf.hibernate.hql.FromParser.token(FromParser.java:101)
at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
at net.sf.hibernate.hql.PreprocessingParser.token(PreprocessingParser.java:123)
at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)

Can any one help
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

FROM NoticeSummary n SET n.transactionStatus = ? WHERE n.referenceNumberCds = ?

This doesn't look like valid HQL. I'd expect it to be something like:
 
Yanbing Yu
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you can re config your hbm.xml,and try again.
 
Mazhar Shaikh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer to the code below that performs a simple update to a column of table.

--------------------------------------
Session sess = HibernateSession.currentSession();
SomeObject obj = (SomeObject) sess.load(SomeObject.class,"PK_ID")); obj.setType("Type");
hibSession.flush();
--------------------------------------

Where,

"SomeObject" is a persistent object that maps to a Database table.
"PK_ID" is a Primary Key value to identify the row to update.

Hope this will help you.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic