-->
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: Statefull Domain Model vs. Offline Domain Model
PostPosted: Wed Apr 28, 2004 6:26 am 
Newbie

Joined: Mon Feb 02, 2004 8:46 am
Posts: 3
In designing our systems we are struggling between using a statefull domain or an offline domain.

I've always wanted a statefull domain but most environments don't support this naturally. Yet it almost a prerequisite for using events and observers as a means of communication between the model and the services.

Hibernate seems especially geared to an offline domain. At the start of the session the model is retrieved and at the end it is persisted. This solves problems as concurrency and transactions and is appropriate for most web based applications.

Yet currently I

_________________
Ralf

* Chaos is a cryptic form of order. *


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 12:03 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I'm not sure what you call a stateful model. If you mean keep a object version between different sessions, you can use the second-level cache.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 11:06 am 
Newbie

Joined: Mon Feb 02, 2004 8:46 am
Posts: 3
emmanuel wrote:
I'm not sure what you call a stateful model. If you mean keep a object version between different sessions, you can use the second-level cache.


Perhaps statefull model is a bad term. I simply meant that if (objectA.id == objectB.id) then (objectA == objectB) must also be true. So within the current JVM exists only one instance of each distinct domain object.

From what I read in the documentation the second-level cache could do this, but I can't find whether it could actually enforce it. Are the objects used directly or are they cloned and merged at each session?

The problem I'm encountering has to do with observers. Below is a fragment of the test code I'm using.

Code:
public class Egg {
   
  // the set of observers, not persistent.
  private Set observers;
   
  // Hibernate id field
  private Long id;
   
  // persistent fields
  private Date hatchtime;
  private int colour;
  private double size;
   
  public void addObserver(EggObserver observer){
    this.observers.add(observer);
  }
   
  protected void notifyHatching(){
    Iterator iter = this.observers.iterator();
      
    while (iter.hasNext()) {
      EggObserver observer = (EggObserver) iter.next();
      observer.hatched(this);
    }
  }
   
  public void Heartbeat(){
    //...
  }

  // ect...
}


When the egg hatches all observers are notified about the event. The observers are not persistent classes and are therefore not persistent. The event must fire once and only once and all subscribers must be notified once.

Would second-level cache help with this?

_________________
Ralf

* Chaos is a cryptic form of order. *


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 6:49 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I really don't understand people needing indetity instead of equality.
The second level cache cannot return you the same instance because of transaction consistency.

PS: identity is obviously something non cluster-safe.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 5:11 am 
Newbie

Joined: Mon Feb 02, 2004 8:46 am
Posts: 3
emmanuel wrote:
I really don't understand people needing indetity instead of equality.


It's because they are not really equal. They start out equal but then continue to diverge until they are merged.

The example I posted above is a bit silly, but I'll try to illustrate. Basically it is a class with a single event. This event triggers at a certain pre-determined time. The object has one observer. This observer sends a notification to the owner of the egg.

Now if i'm currently in a session for changing the object, while concurrently somebody else has a session for building a report of all eggs and the second level cache is enabled.

If the event triggers at this time the observer would receive three notification for the same event. Even worse if in my session i altered the hatch time property to some later time, the actual number of notifications could be even more as two are send now and for all sessions and the cache at a later time again. These notification would not even be consistent with each other.

emmanuel wrote:
The second level cache cannot return you the same instance because of transaction consistency.


That is basically the problem as I see it. Concurrency (and transactions) vs. Events (and a reactive model).

_________________
Ralf

* Chaos is a cryptic form of order. *


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 06, 2004 5:56 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
rwolter wrote:
emmanuel wrote:
The second level cache cannot return you the same instance because of transaction consistency.


That is basically the problem as I see it. Concurrency (and transactions) vs. Events (and a reactive model).

Your event system does not work in a clustered environment.

_________________
Emmanuel


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.