-->
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.  [ 4 posts ] 
Author Message
 Post subject: No updates to DB during session.update
PostPosted: Tue Aug 03, 2004 10:38 pm 
Newbie

Joined: Tue Aug 03, 2004 3:51 pm
Posts: 3
Hi, "party" is a detached object that I subsequently attach. I was
expecting to see some "update sql" when I call the session.update.
There's none !!

Thanks

Session session = PersistenceManager.getSession();

party = new IndividualParty();
party.setUserName("testuser");
party.setPassword("testuserpassword");

IndividualPartyHibernateDAO dao = new IndividualPartyHibernateDAO();
party = dao.find(party);
party.setUserName("changedtestuser");
party.setPassword("changeduserpassword");
session.evict(party);

IndividualParty dsParty = dao.find(party);
session.evict(dsParty);


session.lock(party, LockMode.NONE);

party = dao.update(party);

PersistenceManager.closeSession();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 03, 2004 11:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Well, the "party" is already associated with the session (since you locked it). So at that point, Session.update() is no-op.

Session.flush() is what forces Hibernate to execute sql statements to the DB. I do not see flush() in your code.

This is all covered in the docs.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 11:42 am 
Newbie

Joined: Tue Aug 03, 2004 3:51 pm
Posts: 3
Thanks for the response Steve.

Actually, the dao.update() is implemented as

session.update(object);
session.flush();

I also ensured that the flush is in fact being called.

V


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 04, 2004 12:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
In general, its probably best if you leave "DAO" code out of these posts. You may know what they do, but I assure you we have no clue.

I don't even know where to start. In the middle of this "test" you load some "dsParty" and then promptly do nothing with it. Why? At the very beginning you instantiate a "party" and set some attributes, but then immediately throw that instance away when you do the find. Why?

What is it you are trying to test? Then lets write a test that tests that, and then we can see where your code is broken.

If you are simply trying to test updating of detached objects, then try this:
Code:
// open a session and load a party
Session session = PersistenceManager.getSession();
Party party = // however you get a reference to a party

// make the party detached
session.evict(party);

// now lets change the detached instance
party.setUserName("changedtestuser");
party.setPassword("changeduserpassword");

// and reassociate it with the session
session.update(party);

// finally persist the changes
session.flush();


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