max wrote:
To make a collection behave like a plain vanilla object ?
either call Hibernate.initialize() on it (the safe solution)...
But that just forces a load, doesn't? At least that is what I see.
What if I have an object that has 1000 objects in a collection. I want to work on that object on the web tier, perhaps generate a new collection object.
In a non-hibernate situation, this would be something like:
1) pass back object, with empty collection
2) add to collection
3) pass it back to server tier
4) server tier sees object in collection that does not have a PK--clearly a new object
5) save new collection object
This is exactly the problem we have, and the current hibernate behavior breaks this:
1) pass back object, with empty/uninitialized collection
2) add to collection --- EXCEPTION
We are unable to do anything with the collection instance because it is unintialized and not connected to the session. It just fails.
Perhaps you guys see this as a good idea? That's ok--different strokes for different folks. But the reality is that it keeps people from discarding DTOs then. If the collection is always expecting to be either a) initialized or b) have a valid session to initialize itself, we are going to have to replace it before we send it out to the web tier.
Which really breaks how I would think Hibernate would like us to use it.
Am I just totally misunderstanding something? Do you guys intend it to work this way (either load the whole 1000 objects or never touch it)? Or is this just a use case that never came up initially? Granted, this will only happen in an N-tier situation ... but that is a design you will run into on 50-75% of the time on any large project.
Thanks again for your help!
Matt