-->
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: how to update and modifythe existing record..
PostPosted: Mon Sep 06, 2010 6:11 am 
Newbie

Joined: Sun Sep 05, 2010 5:39 pm
Posts: 9
here which line i have to change..i want to update if record is already exxisted....else i schould be the save...


public String saveorUpdateEntity(CityMasterForm cform,HttpServletRequest request) {
_LOGGER.info("CityMasterDAO :: saveorupdate ");
SessionFactory factory = null;
Session hibernateSession = null;
Transaction transaction = null;
CityMaster cityForm = null;
/*SQLQuery query=Session.createSQLQuery(query);
query.addEntity(policy.class);
query.setString("pcode","c001");

List <Policy> plist=(List<Policy>) query.list();
Iterator <Policy> iterator=plist.iterator();*/

try {
factory = (SessionFactory) request.getSession().getServletContext().getAttribute(HibernatePlugin.KEY_NAME);
hibernateSession = factory.openSession();
transaction = hibernateSession.beginTransaction();
String query="Select * from CityMaster where cityCode='"+cform.getCityCode()+"'" +
" order by cityMasterID desc";
_LOGGER.info("CityMasterDAO :: query :: "+query);
Query qu=hibernateSession.createQuery(query);
List<CityMaster> cityList=null;
cityList=qu.list();

Calendar instance=Calendar.getInstance();
instance.add(Calendar.DATE,-1);
Date yesterday=instance.getTime();
SimpleDateFormat sdfSource = new SimpleDateFormat("dd/MM/yyyy");
String yestday=sdfSource.format(yesterday);
if(cityList.size()>0){
for(CityMaster city :cityList)
{
city.setEffectiveEndDate(yestday);
hibernateSession.saveOrUpdate(city);
hibernateSession.refresh(city);
break;
}

}
else
hibernateSession.save(cform);


Top
 Profile  
 
 Post subject: Re: how to update and modifythe existing record..
PostPosted: Mon Sep 06, 2010 6:14 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Which entity u need to save ?

_________________

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


Top
 Profile  
 
 Post subject: Re: how to update and modifythe existing record..
PostPosted: Mon Sep 06, 2010 7:03 am 
Newbie

Joined: Sun Sep 05, 2010 5:39 pm
Posts: 9
shynate26 wrote:
Which entity u need to save ?


hi dear shynate26

id START_DATE EXPIRE_DATE PCODE
---------- ------------- -------------- ----------
5 23-APR-09 31-JUL-10 p001
6 01-AUG-09 08-NOV-09 p002
7 09-NOV-09 05-AUG-12 p003
8 09-NOV-09 05-AUG-12 p002
9 01-AUG-10 06-JUN-11 p001

here my requirement is using hibernate i want update(using criteria or hql)
1.suppose i have do save or update based on ourrequirement

2.suppose i enter with 10 01-AUG-11 06-JUN-12 p005
this is record is diffrent this is not matching with previous code like p001 or p002 or p003.....
3.so it will inserted...
4.when ever i enter same code like c002...i want update existing record and this record also i have to inserted(here two restictions suppose i entered stardate 09-dec-2016 with p002....in this time
based on p002 code 2 records is available..i want to call max(id) record..

after that we scould set poo2 EXPIRE_DATE is 08-dec-2016(ie means wat i have enter date that one minus-1 as poo2code..


Top
 Profile  
 
 Post subject: Re: how to update and modifythe existing record..
PostPosted: Mon Sep 06, 2010 7:05 am 
Newbie

Joined: Sun Sep 05, 2010 5:39 pm
Posts: 9
chanti576 wrote:
shynate26 wrote:
Which entity u need to save ?


hi dear shynate26 can u plz gve me reply

id START_DATE EXPIRE_DATE PCODE
---------- ------------- -------------- ----------
5 23-APR-09 31-JUL-10 p001
6 01-AUG-09 08-NOV-09 p002
7 09-NOV-09 05-AUG-12 p003
8 09-NOV-09 05-AUG-12 p002
9 01-AUG-10 06-JUN-11 p001

here my requirement is using hibernate i want update(using criteria or hql)
1.suppose i have do save or update based on ourrequirement

2.suppose i enter with 10 01-AUG-11 06-JUN-12 p005
this is record is diffrent this is not matching with previous code like p001 or p002 or p003.....
3.so it will inserted...
4.when ever i enter same code like c002...i want update existing record and this record also i have to inserted(here two restictions suppose i entered stardate 09-dec-2016 with p002....in this time
based on p002 code 2 records is available..i want to call max(id) record..

after that we scould set poo2 EXPIRE_DATE is 08-dec-2016(ie means wat i have enter date that one minus-1 as poo2code..


Top
 Profile  
 
 Post subject: Re: how to update and modifythe existing record..
PostPosted: Mon Sep 06, 2010 7:30 am 
Newbie

Joined: Sun Sep 05, 2010 5:39 pm
Posts: 9
shynate26 wrote:
Which entity u need to save ?

can i have prevoius plz gve me..reply


Top
 Profile  
 
 Post subject: Re: how to update and modifythe existing record..
PostPosted: Mon Sep 06, 2010 8:52 am 
Beginner
Beginner

Joined: Thu Dec 11, 2008 8:18 am
Posts: 35
use flush() before calling refresh().
It is also not advisable to use refresh() in long running session.


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.