Let's say you still want to really abstract hibernate behind a DAO layer and not allow any db-writing from lower layers. But you really don't feel like writing all the DTO's or the code to assemble them.
Couldn't this be done in some soft fashion as follows:
Each DAO method that returns an entity, does this by opening a new session with flushmode never, loads the entity, stores the session hidden in the entity and returns the entity.
You can tamper with the entity all you want, nothing is persisted until you explicitly call the DAO update method which gets the session form the entity and flushes it. If this doesn't happen the session will just be disposed with the entity.
So you get a lot of sessions with isolated graphs, but if they don't overlap too much is that more expensive than one big session?
So what would be achieved? Well, at least something of a quasi DAO where you select graphs to be persisted/updated? I'm a total newbie on ORM, was this a horrible thought?
_________________ /Andreas Karlsson
|