Quote:
By default, Hibernate will not save, create or delete your objects unless you invoke those functions against them (usually in a DAO), so I don't quite understand what the issue is.
Hibernate offers transparent persistence which means that any change to a persistent object is committed to the database when flush occurs. You don't have to call session.save(entity) for the changes to the objects to be persisted.
Quote:
Personally I avoid DTOs like the plague, prefering to use connected domain objects whenever possible, but your needs may be different.
It depends on the type of application you are developing. Usually, only very simple web applications can operate without some kind of disconnected state. As soon as you add things like object validation, you need some way to alert the user without losing their changes. This is where DTO or some form of state object is invaluable.
80% of the time, transparent persistence is very convenient. I'm now focusing on the other 20%.
We are playing with state objects that extend our business objects, but it's just a tremendous waste of time to have these objects which are 99% the same as our domain objects.
It would be much more convenient to flip a switch on the Hibernate SessionFactory to
not persist our entities unless we call save explicitly. Is there a class we can extend to achieve this behavior, or is the framework too integrated with "transparency" to achieve this?
Since the board is plagued with unapreciative comments at time, I'll just add that we are enjoying the framework much, and it saves us a lot of additional work. If I
have to create state objects I will. I was just hoping there may be an approach that give us the best of both worlds. :)