-->
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: problem in converting sql to hql
PostPosted: Sun Sep 05, 2010 6:16 pm 
Newbie

Joined: Sun Sep 05, 2010 5:39 pm
Posts: 9
Hi
could anybody give me appropriate code of HQL or CRITERIA for the following sql code :

UPDATE POLICY
SET EXPIREDATE=STARTDATE-1
WHERE P_CODE=(
SELECT MAX(P_NO)
FROM POLICY
WHERE P_CODE='&PCode'
)
-------------------------------------------
Here is table structure:

P_NO START_DATE EXPIRE_DATE PCODE
---------- ------------- -------------- ----------
5 23-APR-09 31-JUL-10 C001
6 01-AUG-09 08-NOV-09 C002
7 09-NOV-09 05-AUG-12 C003
8 09-NOV-09 05-AUG-12 C002
9 01-AUG-10 06-JUN-11 C001



Top
 Profile  
 
 Post subject: Re: problem in converting sql to hql
PostPosted: Mon Sep 06, 2010 1:07 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Initially load the record you wanted to update and type cast to its corresponding entity. Then using setter method set the date and save the object.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: problem in converting sql to hql
PostPosted: Mon Sep 06, 2010 1:12 am 
Newbie

Joined: Sun Sep 05, 2010 5:39 pm
Posts: 9
shynate26 wrote:
Initially load the record you wanted to update and type cast to its corresponding entity. Then using setter method set the date and save the object.



how to write can u tell me plz


Top
 Profile  
 
 Post subject: Re: problem in converting sql to hql
PostPosted: Mon Sep 06, 2010 2:33 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
I am assuming your Policy entity named as Policy.

List<Policy> entityList = session.createQuery("load_latest_policy","select po from Policy po where po.policyCode=:policyCode order by po.policyNumber desc").setString("policyCode",value).list();

Above statement gives you records having same policy code.

now,
Calendar instance = Calendar.getInstance();
instance.add(Calendar.DATE, -1);
Date yesterday = instance.getTime();

for(Policy entity : entityList )
{
entity.setExpiryDate(yesterday);
session.saveOrUpdate(entity);
session.refresh(entity);
break;
}

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: problem in converting sql to hql
PostPosted: Mon Sep 06, 2010 3:50 am 
Newbie

Joined: Sun Sep 05, 2010 5:39 pm
Posts: 9
shynate26 wrote:
I am assuming your Policy entity named as Policy.

List<Policy> entityList = session.createQuery("load_latest_policy","select po from Policy po where po.policyCode=:policyCode order by po.policyNumber desc").setString("policyCode",value).list();

Above statement gives you records having same policy code.

now,
Calendar instance = Calendar.getInstance();
instance.add(Calendar.DATE, -1);
Date yesterday = instance.getTime();

for(Policy entity : entityList )
{
entity.setExpiryDate(yesterday);
session.saveOrUpdate(entity);
session.refresh(entity);
break;
}



Finally Which one I have to print...


Top
 Profile  
 
 Post subject: Re: problem in converting sql to hql
PostPosted: Mon Sep 06, 2010 3:54 am 
Newbie

Joined: Sun Sep 05, 2010 5:39 pm
Posts: 9

here how to retrive the data .....can u tell me or else using crieria ...show me how to write

can u tell me how to write this code using ctrteria....or projection




chanti576 wrote:
shynate26 wrote:
I am assuming your Policy entity named as Policy.

List<Policy> entityList = session.createQuery("load_latest_policy","select po from Policy po where po.policyCode=:policyCode order by po.policyNumber desc").setString("policyCode",value).list();

Above statement gives you records having same policy code.

now,
Calendar instance = Calendar.getInstance();
instance.add(Calendar.DATE, -1);
Date yesterday = instance.getTime();

for(Policy entity : entityList )
{
entity.setExpiryDate(yesterday);
session.saveOrUpdate(entity);
session.refresh(entity);
break;
}



Finally Which one I have to print...


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.