-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: Not supported for DML operations
PostPosted: Thu Jun 12, 2008 2:46 am 
Newbie

Joined: Wed Mar 19, 2008 3:38 am
Posts: 8
Location: Chennai, India
Hi,

I tried to update a field in the database. It shows me "Not supported for DML Operations.". This is how i create the sessionFactory.
sessionFactory = new Configuration()
.configure("hibernate.cfg.xml")
.buildSessionFactory();

Hibernate version:3.2

Code between sessionFactory.openSession() and session.close():
String queryString = null;
Query query = null;
queryString = "update S set name = :name, description = :description where sID = :sID";
session.beginTransaction();
query = session.createQuery(queryString);
query.setString("name", stackName);
query.setString("description", stackDescription);
query.setInteger("sID", sID);
boolean resultSet;
query.list();
session.getTransaction().commit();


Full stack trace of any exception that occurs:
Exception in thread "main" org.hibernate.hql.QueryExecutionRequestException: Not supported for DML operations [update com.example.example1.db.S set name = :name, description = :description where sID = :sID]
at org.hibernate.hql.ast.QueryTranslatorImpl.errorIfDML(QueryTranslatorImpl.java:272)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:321)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.spikesource.sf.dbaccess.Manager.updateSInfo(Manager.java:82)
at com.spikesource.sf.dbaccess.Manager.main(Manager.java:58)

Name and version of the database you are using:
Postgres:8.2


Last edited by kmsram420 on Wed Jun 18, 2008 5:54 am, edited 2 times in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 1:10 am 
Newbie

Joined: Wed Mar 19, 2008 3:38 am
Posts: 8
Location: Chennai, India
There is an other way of updating the row in a table.

Code:
session.beginTransaction();
S s = (S)session.get(S.class, sID);
s.setDescription(sDescription);
s.setName(sName);
session.update(s);
session.getTransaction().commit();


And this works.


Last edited by kmsram420 on Wed Jun 18, 2008 5:55 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 7:35 am 
Newbie

Joined: Sat May 03, 2008 12:30 pm
Posts: 9
Hi,
Try query.executeUpdate()


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 7:36 am 
Newbie

Joined: Sat May 03, 2008 12:30 pm
Posts: 9
Hi,
Try query.executeUpdate()


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 17, 2008 3:31 pm 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Quote:
public int executeUpdate()
throws HibernateException

Execute the update or delete statement. The semantics are compliant with the ejb3 Query.executeUpdate() method.

Returns:
The number of entities updated or deleted.
Throws:
HibernateException



JavaDoc for the Hibernate3 Query object:

http://www.hibernate.org/hib_docs/v3/api/index.html[/code]

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 18, 2008 12:23 am 
Newbie

Joined: Wed Mar 19, 2008 3:38 am
Posts: 8
Location: Chennai, India
Hey thanks....executeUpdate() works :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.