-->
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.  [ 10 posts ] 
Author Message
 Post subject: I dont want setter update database after load!!!
PostPosted: Wed Nov 09, 2005 11:49 am 
Beginner
Beginner

Joined: Tue Jul 12, 2005 1:50 pm
Posts: 26
Hibernate version: 3

I want to load an object like credit card table from db . set the number as decrypted one and send it to view layer to show it. But after set, it sets it in data base also. I dont want to set in db.
How can I stop it?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 11:51 am 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
You are probably running into auto-flush. Read about FlushMode here:
http://www.hibernate.org/hib_docs/v3/ap ... hMode.html

and here:
http://www.hibernate.org/hib_docs/v3/re ... e-flushing

Try setting FlushMode.COMMIT on the session and see if that solves your problem.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 12:02 pm 
Newbie

Joined: Mon Oct 03, 2005 8:27 am
Posts: 13
I have another solution..
1. CreditCard cc = currSession.get(CreditCard.class, new Integer(id));
2. tx.commit();
3. session.close();
4. //At this point cc is a detached object...
5. cc.setCode(yourCode);


etc...

I'm a newby so, If I'm making a mistake, please let me know!

I learn from my mistakes!

By(te)

Nico


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 12:10 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
you might want to set update="false" for the property in the mapping file.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 12:17 pm 
Newbie

Joined: Mon Oct 03, 2005 8:27 am
Posts: 13
Quote:
you might want to set update="false" for the property in the mapping file.


Why disable update at mapping level just for a particular scenario?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 12:21 pm 
Beginner
Beginner

Joined: Tue Jul 12, 2005 1:50 pm
Posts: 26
Actually, I am using jta . so I dont handle transaction management in my code. But I tried session.close() , session.evict(CreditCard) , session.clear() before set , but none of them worked.

Right now I tried session.setFlushMode(FlushMode.NEVER) and COMMIT as you said, but didnt work also.

I tried <attribute name="FlushBeforeCompletionEnabled">false</attribute> in my jboss-service.xml. It didnt work also.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 12:36 pm 
Beginner
Beginner

Joined: Tue Apr 05, 2005 4:27 pm
Posts: 40
Location: canada
Quote:
Why disable update at mapping level just for a particular scenario?


i said might. :) depends on the situation, if it's something like a credit card number that wouldn't change once it's been inserted.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 12:43 pm 
Beginner
Beginner

Joined: Tue Jul 12, 2005 1:50 pm
Posts: 26
Thank you ,
I tried update="false" and it worked for this situation, but I dont know the solution for some attributes that are updatable after insertion.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 1:25 pm 
Senior
Senior

Joined: Mon Apr 04, 2005 8:04 am
Posts: 128
Location: Manchester, NH USA
Just calling the setter method should not cause -anything- to happen with the database. Read the Hibernate docs on when flushes occur (when things are actually changed in the database). Session.evict should work fine -- are you sure you're passing in the right object. Posting code would probably help a lot at this point, since you've received a few good suggestions that you claim are not working.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 1:44 pm 
Beginner
Beginner

Joined: Tue Jul 12, 2005 1:50 pm
Posts: 26
private List<PaymentCcards> decryptCcList(List<PaymentCcards> pcc){
PaymentCcardsDAO dao = new PaymentCcardsDAO();
List<PaymentCcards> ret = new ArrayList<PaymentCcards>();
Encrypter encrypter = new Encrypter();

// here getSession().clear() or close() didnt work also
for (PaymentCcards pc : pcc) {
//dao.getSession().evict(pc); //this evict didnt work
try {
if(pc.getNumber()!=null && pc.getNumber().trim().length()>0){
String decryptednumber = encrypter.decryptdata(pc.getNumber());
pc.setNumber(decryptednumber);
ret.add(pc);
}
}
catch (Exception e) {e.printStackTrace();log.error(e.getMessage());}
}
return ret;
}


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