I want to write an efficient transformer, that will transform a JPA (1.0) entity to my transfer object and that:
- will be called in a transactional context,
- will cause no extra DB interaction, that is will transform only what's already loaded.
I cannot use the construct if (entity.getSomething() != null)
as "something" will get loaded.
The only thing I can think of is having the transformer spawn a new transaction, reload the entity in the new transaction's context and commit it — and then working on a detached entity. It does involve a reload, though. Any cleverer ideas?