File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Update Query in Hibernate (Please Help)" Watch "Update Query in Hibernate (Please Help)" New topic
Author

Update Query in Hibernate (Please Help)

sagili mohan
Greenhorn

Joined: Jul 12, 2005
Posts: 1
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

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
Greenhorn

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


java lover
Mazhar Shaikh
Greenhorn

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



Terminator
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Update Query in Hibernate (Please Help)
 
Similar Threads
how to save collection object into database
Hibernate:Problem in updaing data to the database
Hibernate- why my query results are caching?
Finding the total result size using Hibernate Query and pagination
Cannot perform SQL UPDATE null