From: Sven W. <s_...@in...> - 2002-03-15 01:07:30
|
<quote from=http://sourceforge.net/forum/forum.php?thread_id=652104&forum_id=128638> We should continue this discussion in the devel list. Could you please post a summary of the needed functionality and your suggested solution to the devel list, so we can start a proper discussion there? There are a couple of questions remaining in my head which I need to run past everyone.... </quote> The problem: If you want to use hibernate with stateless session beans you have to make sure that you do everything at once within the session bean because when the object under (hibernate)session control leaves the (ejb)session bean via serialization there is no way to get this object back into the database. What we need: There has to be a mechanism that would allow us to get an object in/out of a session with enough additional information that another session could use the object as is would've be loaded normally. This has to be also possible for object graphs but there should be a possiblity to restrict the object graph because if you load the whole graph you might have the whole database in the graph. The serialized objects + additional information should be minimal because bandwidth is often a problem in distributed systems. Some ideas for a solutions: (warning: I only had a look at the sources for about an hour) Currently hibernate maintains the complete state of an object within a session. One solution would be to put the additional state information that is needed in the persisted object: interface MovableObject { public setState (Object o); public getState (Object o); } Every object that needs to be passed around has to implement this interface. Within a session there are some branches like this: if (o instanceof MovableObject) o.get/setState(....) else { // This object is not movable so do as we've done before ... } For "normal" objects nothing changes and everything is managed and saved in the session. This is the approach I'm currently using: public MyClass implements java.io.Serializable,PersistentLifecycle, java.lang.Cloneable { ... public void saveValues () { try { oldValues = (MyClass)this.clone(); } catch (Exception ex) {} } public MyClass getSavedValues () { return oldValues; } public void load(Session session) throws java.sql.SQLException,HibernateException { saveValues (); } } Session: void reassign (Object new, Object old); e.g. session.reassign (o, o.getOldValues); void reassign (Object new, boolean isDirty); It is VERY useful to have the old values around because you often have to do comparisons old vs. new. This should also be implemented in hibernate but for "Movable" objects it should be possible to get the old state without the need of a real session. For some movable objects it might be useful to do not keep an additional state because you know when these objects are dirty which saves bandwidth and coding time. Transactions: It should be possible to have everything versioned to archive transaction isolation. Non versioned writes should also be allowed: (e.g. this is useful if you want to do cross database replication between different application servers). bye Sven |