-->
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.  [ 12 posts ] 
Author Message
 Post subject: Hibernate3 and update with HQL
PostPosted: Mon May 16, 2005 4:57 pm 
Regular
Regular

Joined: Tue Jan 11, 2005 8:55 pm
Posts: 53
Hi,

I'm using Hibernate3, and can someone please tell me *clearly* or point to documentation that *clearly* states how to do an update using HQL or a native sql query?

I've searched the documentation and searched the forums, and I cannot get a clearcut answer if

a) Hibernate 3 allows you to do updates using HQL/sql query

b) do i have to use createQuery() or createSQLQuery(), or do they both work?

b) If yes, an example.

Basically, I want to do something like:

Code:
session.createSQLQuery("UPDATE {c} Consumer {c} SET CONSUMER_STATUS = :newstatus WHERE CONSUMER_ID = :consumerId)
                              .addEntity("c", Consumer.class)
                           .setString("newstatus",statusMessage)
                              .setLong("consumerId",id)
                              .list();


I honesly can't find a simple clearcut answer, anywhere.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 5:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
native sql queries does not yet support update/deletes.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 5:18 pm 
Regular
Regular

Joined: Tue Jan 11, 2005 8:55 pm
Posts: 53
max wrote:
native sql queries does not yet support update/deletes.


Thank you. Do HQL queries support update/deletes?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 5:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes - look in docs for executeUpdate() (in H3)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 5:39 pm 
Regular
Regular

Joined: Tue Jan 11, 2005 8:55 pm
Posts: 53
max wrote:
yes - look in docs for executeUpdate() (in H3)


Thanks Max, that is *exactly* what I was looking for.

Question, I don't know what I'm doing wrong. When I run this statement, my application completely crashes:

Code:
         session.createQuery("update Consumer set status = 'aaa' where consumerId = " + id)
//                              .setString("newStatus", status)
//                              .setLong("idValue", id)
                              .executeUpdate();


My Consumer object has status as a member, and consumerId is the primary key.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 6:35 pm 
Regular
Regular

Joined: Tue Jan 11, 2005 8:55 pm
Posts: 53
By the way, forgot to include the error:

CharScanner; panic: ClassNotFoundException: org.hibernate.hql.ast.HqlToken

I'm using ant-antlr-1.6.3.jar - should I be using another version?


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 16, 2005 11:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ant-antlr is for the build process, you need antlr-1.6.3H3.jar (see the readme.txt/version.properties for details)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 17, 2005 4:11 pm 
Regular
Regular

Joined: Tue Jan 11, 2005 8:55 pm
Posts: 53
max wrote:
ant-antlr is for the build process, you need antlr-1.6.3H3.jar (see the readme.txt/version.properties for details)


Thanks, so I'm using antlr-2.7.5H3.jar, and I still continue to get this error:

CharScanner; panic: ClassNotFoundException: org.hibernate.hql.ast.HqlToken

I'm putting this jar file in the same spot as all the other hibernate jars. Why am I getting this error?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 17, 2005 4:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
how are you running this ? from the distribution or a cvs checkout ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 17, 2005 4:43 pm 
Regular
Regular

Joined: Tue Jan 11, 2005 8:55 pm
Posts: 53
max wrote:
how are you running this ? from the distribution or a cvs checkout ?


From the distribution. I'm running it in Weblogic 8.1, and I'm including that jar with the other necessary runtime jars at the ear level. Everything works fine until I run an executeUpdate() statement (as mentioned above) and it completely crashes with that error: charscanner, panic ....

What am I doing wrong?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 17, 2005 5:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ah weblogic - they have a broken antlr in their lib directory. you need to place the antlr from h3 dist in there.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 17, 2005 5:03 pm 
Regular
Regular

Joined: Tue Jan 11, 2005 8:55 pm
Posts: 53
max wrote:
ah weblogic - they have a broken antlr in their lib directory. you need to place the antlr from h3 dist in there.


Hi Max, thanks for your help. I found this bullet, under the migration guide, that was helpful:

Code:
16.   On BEA, you have to move antlr-2.7.5H3.jar to the PRE_CLASSPATH of
the server to run inside BEA because BEA includes this tool in their
system classpath that is inconsistent.




Thanks!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.