By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,873 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,873 IT Pros & Developers. It's quick & easy.

Hibernate :One-to-one association must return null instead of proxy (or actual object

P: 15
I have posted this question in hibernate forums also.. As this forum is related to java, i am posting it here also ...

In hibernate, presently one-to-one associations are fetched non-lazily...
I know that this is done because, hibernate requires to fire 1 sql to find whether proxy can be created or not...
and if it has to fire 1 sql, then why not to load one-to-one object itself in 1 sql instead of creating proxy of it (in 1 sql).

Consider my scenario..
Product has one-to-one with ProductBasic which has one-to-one with ProductTerm

Now i just queried for List of Products and i got say 300 product records.. (in 1 sql query)
In this case i don;t require ProductBasic and ProductTerm.... but as these are one-to-one associations, there are
compulsorily non-lazily fetched. Thus another 300 + 300 select queries are fired to get ProductBasic and ProductTerm
which is surely unacceptable as there are 600 extra sql's getting fired.. The situation may become worst if i
have many one-to-one associations in my domain tree.

I think hibernate code must be changed so that one-to-one associations should be not compulsorily non-lazily fetched....

One way i could think of it is, if user has not asked to fetch one-to-one association then instead of
loading one-to-one object (or creating proxy) simply null should be returned without firing any SQL...
Later when user asks for this one-to-one association, now fire 1 sql to get this association..

The major advantage of this approach is that if user has not asked for one-to-one association, no extra sql (unnecessary)
queries will be fired... (specially when retriving parent collection - e.q our scenario described above)..

This critial problem will always occur when we fetch any collection in the domain tree...
All it's one-to-one associations will be compulsorily fetched for 'n' records. and as n increases, the problem becomes severe..

As per my knowledge, this problem is so critical and severe, that if not solved, nobody will be able to use hibernate
efficiently (and acceptably) in real J2EE applications and hence i request for an immediate solution for this problem..
Jun 18 '09 #1
Share this Question
Share on Google+
1 Reply

P: 13,264
But there are already lots of people using hibernate "efficiently (and acceptably) in real J2EE applications".
As I already told you before, this is not the place to be posting change requests to hibernate. None of us here have much to do with how hibernate is implemented. Contact for that.
Jun 18 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.