File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Update Query in Hibernate (Please Help) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Update Query in Hibernate (Please Help)" Watch "Update Query in Hibernate (Please Help)" New topic

Update Query in Hibernate (Please Help)

sagili mohan

Joined: Jul 12, 2005
Posts: 1

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 n SET n.transactionStatus = ? WHERE n.referenceNumberCds = ?]
at net.sf.hibernate.hql.FromParser.token(
at net.sf.hibernate.hql.ClauseParser.token(
at net.sf.hibernate.hql.PreprocessingParser.token(
at net.sf.hibernate.hql.ParserHelper.parse(

Can any one help
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

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

This doesn't look like valid HQL. I'd expect it to be something like:

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Yanbing Yu

Joined: Aug 31, 2003
Posts: 9
Maybe you can re config your hbm.xml,and try again.

java lover
Mazhar Shaikh

Joined: Aug 13, 2002
Posts: 2
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");


"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.

I agree. Here's the link:
subject: Update Query in Hibernate (Please Help)