-->
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.  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Proxy initialisation across a network
PostPosted: Sat May 01, 2004 9:08 am 
Beginner
Beginner

Joined: Sat May 01, 2004 2:44 am
Posts: 32
Location: Brisbane, Australia
There has been much discussion on various threads about the problems encountered when lazily loading object relationships across a network. Basically, it seems that as soon as the proxy is serialised and transmitted to a remote tier, it loses its connection to the session and cannot initialise itself when required.

It appears to me that this imposes a great restriction on lazy loading. Its a great feature that allows you the freedom to develop a complex object model, without a large tree of objects being loaded for every data record. But unfortunately, it can only be leveraged by code running in the same JVM.

I can see that the proxy classes (eg. CGLIBLazyInitializer) have a reference to a SessionImplementor that loads its state when required. Would it be possible, or for that matter, desirable, to have object and collection proxies refer to a Remote handler instead, that could call the session in another tier to load its state as needed?

Note that I am not implying non-transactional loading, as this proposed proxy functionality would only work within an open session, much like the 'Open Session in View' pattern.

I can see that someone else has done something similar (http://article.gmane.org/gmane.comp.jav ... evel/1433/), except it appears they use these proxies for every object that's loaded.

Scott


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 01, 2004 11:22 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Remember that your primary option is to fetch all required data (the subgraph you need) before you pass back to the client tier! Hibernate has very flexible fetching, with HQL and Criteria. Lazy loading is the second option and I'm not convinced that it makes sense across tiers. We've been thinking about that several times, and any "automatic" lazy loading with a new Session would break transactions (Detached Objects pattern requires version checking).

Your approach, with a single Long Session (disconnect/reconnect pattern) per application transaction, may be valid, but I really fear that users don't understand it and use it instead of fetching. Why not implement a patch and discuss the implications of that on the developer list?

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


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 01, 2004 11:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Session.lock()


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 01, 2004 11:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Why not implement a patch and discuss the implications of that on the developer list?


Absolutely not. I am an immediate veto to anything like this.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 01, 2004 12:46 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
I think it must be trivial to implement "outside" hibernate, implement wrapper for session as statefull bean and return custom proxies from "remote session",
you can use custom proxy for "remote session" on client too for more fun.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 02, 2004 11:41 pm 
Beginner
Beginner

Joined: Sat May 01, 2004 2:44 am
Posts: 32
Location: Brisbane, Australia
christian wrote:
Remember that your primary option is to fetch all required data (the subgraph you need) before you pass back to the client tier! Hibernate has very flexible fetching, with HQL and Criteria. Lazy loading is the second option and I'm not convinced that it makes sense across tiers. We've been thinking about that several times, and any "automatic" lazy loading with a new Session would break transactions (Detached Objects pattern requires version checking).

Your approach, with a single Long Session (disconnect/reconnect pattern) per application transaction, may be valid, but I really fear that users don't understand it and use it instead of fetching. Why not implement a patch and discuss the implications of that on the developer list?


The advantage I had seen with lazy loading across the tiers was that a GUI could allow users to "turn off" unwanted data for viewing in preferences. The client layer could leverage lazy loading to only retrieve data that was required.

I guess one alternative is to have the client specify what data to fetch. Another is to have the service layer return the maximum sub-graph likely to be needed. I will probably go with one of these latter options.

I had a look at CarrierWave. While I liked the ability to specify a fetch depth and 'fuzzy' ends (ie. ends that are remote references), I didn't like the code-generation approach, and I found the whole architecture overkill for what I was looking to achieve.

On a side note, I think a useful api would be something similar to CarrierWave (or Service Data Objects), with the ability to specify (in configuration or in API), at a fine level which properties should be copied by value, and which should be made remote calls. The proxy object transmitted to the client side would need to record any changes made to the copy-by-value data (ie. by the client), and transmit all these changes prior to any calls to the remote method calls, to synchronise its state with the remote POJO. The advantages would be that rich domain models could be modeled and transmitted to the client without the client needing all the support classes on the classpath, and the network traffic could (hopefully) be reasonably efficient. But then again, this all could be an unnecessarily complicated alternative to a well-designed service layer.


gavin wrote:
Quote:
Why not implement a patch and discuss the implications of that on the developer list?


Absolutely not. I am an immediate veto to anything like this.


Just curious, but what are the objections to this?

Scott


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 4:45 pm 
Pro
Pro

Joined: Mon Sep 08, 2003 4:30 pm
Posts: 203
Hi all,

I am also perplexed by the hibernate team resistance to extending lazy loading across tiers.

Several J2EE implementations AND JDO implementations already support this.

So why not Hibernate?

TIA,

--steve p.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 5:44 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Quote:
Several J2EE implementations AND JDO implementations already support this.

So why not Hibernate?


here in america, mothers have a favorite saying: "If your friends jumped off a bridge, would you too?". Meaning, just because others do it does not necessarily make it right.

The issue has to do with transactions. The problem is that a lot of programmers (for whatever reason) tend to only think of write consistency when they hear the term transactions. But there is another side to that coin, namely read consistency or transaction isolation.

In order to facilitate lazy loading across tiers, you would also have to facilitate lazy loading outside of transactions. That is more the concern.


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

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is a definite misfeature, as has been discussed many times. Fetching data piecemeal across the network does not scale, and breaks transaction isolation.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 8:27 pm 
Beginner
Beginner

Joined: Sat May 01, 2004 2:44 am
Posts: 32
Location: Brisbane, Australia
steve wrote:
The issue has to do with transactions. The problem is that a lot of programmers (for whatever reason) tend to only think of write consistency when they hear the term transactions. But there is another side to that coin, namely read consistency or transaction isolation.


I have seen Gavin and others write that data reading should always be done within a transaction. And I know that JDO enforces this (all operations occur within a transaction), whereas Hibernate doesn't (it is possible to do reads or writes outside a transaction).

My question then is, if you are not updating the data until later, do you gain anything by reading within a transaction?


steve wrote:
In order to facilitate lazy loading across tiers, you would also have to facilitate lazy loading outside of transactions. That is more the concern.


Not if you are only reading it first (and maybe upating it later). And besides, transaction isolation issues will still arise across tiers, since (typically) a client wants to read the data, modify it, then transmit the changes back to the server. Ideally all three processes would occur within a single transaction, but this opens up the risk that the client might die and leave the transaction hanging. So in any event, you are still limited to reading and writing in separate transactions anyway.

Scott


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 10:51 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
There is no database access outside of a transaction, ever.

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


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 03, 2004 10:52 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Oh, and you have to update yourself on "application transactions", optmistic concurrency and automatic version checking.

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 12:45 am 
Beginner
Beginner

Joined: Sat May 01, 2004 2:44 am
Posts: 32
Location: Brisbane, Australia
christian wrote:
There is no database access outside of a transaction, ever.


Ok, I didn't realise that. Do you mean that a call to Session.list() starts a transaction if one is not already begun, or that an exception will be thrown if no transaction is current?

christian wrote:
Oh, and you have to update yourself on "application transactions", optmistic concurrency and automatic version checking.


I have read the docs on this, but I am still unsure how Hibernate does version checking if you don't specify a version number or timestamp column. Do you just check against all original loaded values within the update statement?

Scott


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 1:08 am 
Beginner
Beginner

Joined: Sat May 01, 2004 2:44 am
Posts: 32
Location: Brisbane, Australia
Scott wrote:
I have read the docs on this, but I am still unsure how Hibernate does version checking if you don't specify a version number or timestamp column. Do you just check against all original loaded values within the update statement?


I have just seen in the docs for <class> where it says that you can only do optimistic locking on column values (as opposed to versioning) when dynamic-update = true. And I see in the source code that you can't do optimistic locking on column values with joined-subclass mappings either. So I guess that answers my question.

Scott


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 3:22 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is not Hibernate specific, but you simply can't communicate with a database outside of a database/system transaction.

_________________
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.  [ 16 posts ]  Go to page 1, 2  Next

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.