jQuery in Action, 3rd edition
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 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

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: http://aspose.com/file-tools
subject: Update Query in Hibernate (Please Help)
It's not a secret anymore!