-->
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.  [ 8 posts ] 
Author Message
 Post subject: auto detached objects mode
PostPosted: Fri Jul 29, 2005 12:46 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
Im in hibernate 3, and have a general question. If this is in the docs, kindly point me to which one.

This is my understanding of how hibernate works (in pseudocode):

1. retrieve an object
2. edit the object
3. insert an object into the session
4. close and commit

Both objects will get persisted to the DB (the one that was retrieved and edited, and the one that was explicitly inserted).

This is how I am considering going (since I want to reduce the magic happening to make DB stores explicit).

In the same 4 steps above, only the inserted object gets persisted. To get both to be persisted, you do this:

1. retrieve an object
2. edit the object
3. insert an object into the session
4. store the retrieved and edited object
5. close and commit

So basically all retrieved objects are detached by default. And I realize this kills any caching. Thats ok. Is there a setting to do this be default or do I need to detach after retrieving each one?

Thanks,
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 7:08 am 
Senior
Senior

Joined: Tue Jun 21, 2005 10:18 am
Posts: 135
Location: South Carolina, USA
If you don't close the session before editing the object, then there is no setting that I am aware of. I believe you will need to dissociate it from the session. Look at session.evict(object).

I have to admit, though, I don't understand why you would want to do this in the first place...


Top
 Profile  
 
 Post subject: Re: auto detached objects mode
PostPosted: Fri Jul 29, 2005 7:25 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
mchyzer wrote:
Im in hibernate 3, and have a general question. If this is in the docs, kindly point me to which one.

This is my understanding of how hibernate works (in pseudocode):

1. retrieve an object
2. edit the object
3. insert an object into the session
4. close and commit

Both objects will get persisted to the DB (the one that was retrieved and edited, and the one that was explicitly inserted).

This is how I am considering going (since I want to reduce the magic happening to make DB stores explicit).

In the same 4 steps above, only the inserted object gets persisted. To get both to be persisted, you do this:

1. retrieve an object
2. edit the object
3. insert an object into the session
4. store the retrieved and edited object
5. close and commit

So basically all retrieved objects are detached by default. And I realize this kills any caching. Thats ok. Is there a setting to do this be default or do I need to detach after retrieving each one?

Thanks,
Chris


5. commit Tx THEN close Session

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject: Re: auto detached objects mode
PostPosted: Fri Jul 29, 2005 9:45 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
pksiv wrote:
5. commit Tx THEN close Session


I still have the problem of auto flush sending statements to the DB. I dont want autoflush off (I think, since do all update/store/inserts flush?), I just want the objects detached automatically.

Thanks,
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 9:48 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Query.setReadOnly(true)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 30, 2005 12:15 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
christian wrote:
Query.setReadOnly(true)


I need to revoke my helpful rating, I should have tried this before rating. :) JK. Seriously though I used this, and when reattaching to the session it will not let me, per my example above? I tried to store() to the same session and it ignored them. This is definitely not what I am looking for, and I do not really see why it works like that. Oh well, agree to disagree. I will just manually detach each object selected in my Hibernate-wrapper framework unless there is another suggestion... Thanks, Chris


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 30, 2005 12:26 am 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
btw, it would be nice to not have to make a dirty checking listener, just a global param that says "do not dirty check"


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 30, 2005 6:13 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Interceptor.findDirty()


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.