-->
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.  [ 5 posts ] 
Author Message
 Post subject: Execute a UPDATE by QUERY
PostPosted: Mon Nov 14, 2005 12:23 pm 
Newbie

Joined: Wed Oct 26, 2005 1:29 pm
Posts: 9
Location: brazil
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Is posible execute a update like this:


Code:
public static void expiraPreReserva() throws HibernateException, ParseException {
            
      Session sess = SessionFactory.currentSession();
      Transaction tr = sess.beginTransaction();   
      
      Query q = sess.createQuery( "UPDATE TPreReserva SET status='E' where dataFpr < ?" );
         
      q.setDate( 0, EuroUtil.getDataAtual() );
      q.list();
      
      tr.commit();
      SessionFactory.closeSession();
   }


but this throws the exception:
net.sf.hibernate.QueryException: query must begin with SELECT or FROM: UPDATE [UPDATE TPreReserva SET status='E' where dataFpr < ?]


Thanks JP


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 12:31 pm 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
No.

query must begin with SELECT or FROM


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 12:32 pm 
Newbie

Joined: Wed Oct 26, 2005 1:29 pm
Posts: 9
Location: brazil
So how can i make a update like that??


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 12:40 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
you can use direct jdbc using session.connection(), or session.createSqlQuery might work

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 14, 2005 12:43 pm 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
Or upgrade to hibernate 3.x


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