-->
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.  [ 3 posts ] 
Author Message
 Post subject: how to place sequence query in hibernate in .hbm.xml
PostPosted: Tue Jun 16, 2009 3:43 am 
Newbie

Joined: Fri Jan 16, 2009 8:40 am
Posts: 7
Hi,

In my project i have a sequence query in DB2,where i get nextval from a sequence.

I want to know can i place it in .hbm.xml file & how can i access this in my code.


Nisha


Top
 Profile  
 
 Post subject: Re: how to place sequence query in hibernate in .hbm.xml
PostPosted: Tue Jun 16, 2009 5:18 am 
Beginner
Beginner

Joined: Wed Dec 10, 2008 5:59 am
Posts: 47
Hi,

In general you place named queries after the </class> tag in your .hbm.xml files. I assume that your sequence query simply is a regular query (and queries which are placed in your hm.xml files are also called named queries).

MAPPING FILE:
Code:
 
[...]
     </class>
     <sql-query name="stakeholderChanged">
          UPDATE track
          LEFT JOIN share ON track.id = share.track_id
          LEFT JOIN stakeholder ON stakeholder.id = share.stakeholder_id
          SET track.flag = :flag
          WHERE stakeholder.id = :id
     </sql-query>
</hibernate-mapping>


CODE:
Code:
public void executeStakeholderChanged(Stakeholder s) {
     org.hibernate.Query q = getSession().getNamedQuery("stakeholderChanged");
     q.setInteger("flag", Stakeholder.FLAG_UPDATED);
     q.setString("id", s.getId().toString());
     q.executeUpdate();
}


Top
 Profile  
 
 Post subject: Re: how to place sequence query in hibernate in .hbm.xml
PostPosted: Thu Jun 18, 2009 12:22 am 
Newbie

Joined: Fri Jan 16, 2009 8:40 am
Posts: 7
Thanks.It worked


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