-->
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.  [ 15 posts ] 
Author Message
 Post subject: isModified() concept
PostPosted: Sun Feb 15, 2004 2:38 pm 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
Does Hibernate support something like the "isModified concept"?

Lets explain what I mean:
Code:
A a = (A)session.load(A.class, id);
session.save(a);

1. Does Hibernate execute a update on the database in this case? I mean, no modification was done after loading the object.

Next example:
Code:
A a = (A)session.load(A.class, id);
a.setInt(a.getInt() + 1);
a.setInt(a.getInt() - 1);
session.save(a);

1. Similiar Question: Does Hibernate execute a update on the database in this case? A modification was done, but the second modification has the effect that there was not really a modification.

Any persistance should only be done if the object has been modified.

3. Is Hibernate smart enough to know whether there have been modifications? Or do I have to implement my own detection of modification?
Code:
A a = (A)session.load(A.class, id);
a.setInt(a.getInt() + 1);
a.setInt(a.getInt() - 1);
if (a.isModified())
{
  session.save(a);
}


I ask these questions because I want to achieve good performance.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 15, 2004 4:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Yes, Hibernate supports automatic dirty checking. Please read the Hibernate documentation TIA.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 15, 2004 5:32 pm 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
gavin wrote:
Yes, Hibernate supports automatic dirty checking. Please read the Hibernate documentation TIA.


Okay, I have to test it myself. I tried to explain what I mean but I was misunderstood as it seems.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 15, 2004 11:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No you were not misunderstood.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 1:33 pm 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
Maybe it solves my problem.

I thought how could I implement the persistance for our batches with Hibernate.

Now we are the only users of a persistance framework which wraps Entity Beans. The Value Objects (infact they are Business Objects) all extend AbstractValueObject. This class provides a method called "isModified())".

In the batch we use a fast lane reader which reads rows from the old world's database. They don't use objects in the old world. Inside the batch we make objects and persist them to the new world's database.

We load the object from the new world's database, for example an Article with articleId "4711". Then we copy all the attributes from the migrated object to the loaded object. If the loaded object was modified by this procedure, we save it to the new world's database. Thats what the isModified() method is good for. If the object was meanwhile changed by another comitted transaction in the new world's database, a MeanwhileChangedException is raised during saving.

You may wonder about that solution. But I didn't choose the framework we have to use and which includes an own persistance layer.

Hibernate seems to have a different concept which makes such a way which I described unnecessary. It seems that there is no use for such a method like isModified() in the Hibernate world.

Let me ask you two questions:
1. What means TIA?
2. Does Hibernate have a similiar state change model like JDO (transient, persistant-new, persistant-dirty, hollow and so on)? I mean there are methods to check the state of persistant capable classes. If a rollback occurs, the objects are rolled back in memory too. Or can you tell me a page where all the differences and similiarities are listed between Hibernate and JDO?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 1:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
TIA= Thanks in Advance

Yes, the concept of thinks like transient, disconnected, persistant etc. apply to every OR-Mapper. There is however no explicit way to retrieve that states in Hibernate. Basically a good OR mapper (which Hibernate is) should be able to handle peristance in a way that you don't need any of that explicit state management.

Hibernate does not support in-memory-rollback of peristent objects, because it would impose a large performance penalty. You have to do that yourself in cases where this is really needed.

There is a comparison of various OR-Mappers here: http://c2.com/cgi-bin/wiki?ObjectRelationalToolComparison


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 2:33 pm 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
Thanks for the reply.

I never tell people RTFM. So often I read the FAQs of some pages only to check that my question is not answered there.

Imagine how it would be of a sales clerk if you ask him in a really big supermarket where you can find this or that and he answers you to search it yourself.

Or if a pupil ask a question and the teacher tells him to read it in the encyclopaedia.

Its simple and remember me: If you think RTFM, don't bother to reply to my thread.

I'm happy to help other people in forums, even if they have "stupid" beginner questions.

Gavin, maybe we had a bad day.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 2:36 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Cool down. Read the instructions for this forum, read the documentation we recommend. Almost anything about Hibernate is documented in a written form and we don't like copy/paste.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 2:44 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
quereinsteiger wrote:
Or if a pupil ask a question and the teacher tells him to read it in the encyclopaedia.

Actually I'm intended to think this teacher is a good one, but it's a personal opinion :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 5:39 pm 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
Lets agree on something. I will not change myself in this respect.

You are free not to reply to my questions if you thing RTFM.

If you reply to me, then please not in the way that I feel guilty of having asked the question.

Of course its okay to tell me where there is written something. If I am interested in details, I maybe study the topic, digging deeper.

I think this is a good deal for both sides. I prefer not to get answers than to get answers which make me feel guilty of having asked the question.

I don't want to offend someone. I just look for a deal with the Hibernate team (Gavin, Christian and Emmanuel).

If we can agree on this deal without fruitless discussions, I can live with this solution.

I consider silence as consent.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 3:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
OK, so let me explain some things:

(1) I am not a sales assistant. You are not about to purchase something from me. So your analogy is broken.

(2) If we do not respond to a thread, then someone else comes along in one month time, searches the forum, pulls up your ancient question, sees it has no answer and then post something useless like "I have the same problem, is there any solution yet?????". Actually, when we don't respond, usually the user pushes the post back up to the top the next day. Hence we have to respond to every post.

(3) I was not rude to you; I answered your question, and told you that you should do more reading. RTFM is an absolutely acceptable response in a high-traffic forum like this one.

(4) We make the rules of the forum, not you. If you don't like this, you are free to go elsewhere.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 22, 2004 2:44 pm 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
I got my answers here, so I ignore you trying to offend me.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 22, 2004 2:47 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Es kann auch daran liegen, dass Dein Englisch nicht gerade frei von einem negativen Unterton ist. Lass das doch einfach weg.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 22, 2004 3:00 pm 
Regular
Regular

Joined: Sat Oct 11, 2003 11:13 am
Posts: 69
christian wrote:
Es kann auch daran liegen, dass Dein Englisch nicht gerade frei von einem negativen Unterton ist. Lass das doch einfach weg.


Okay, ich werde sehen, wie sich das entwickelt. Vorhin habe ich mich ziemlich aufgeregt.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 22, 2004 3:02 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Einfach Zeit nehmen, Hibernate ist nicht gerade ein kleines Framework. Die Anleitung ist tatsaechlich wichtig, ohne geht nix. Da wir hier jeden Tag hunderte von Fragen beantworten, merken wir ganz schnell wenn jemand die Dokumentation nicht liest, das kann schonmal patzig werden.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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