Frage

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?

War es hilfreich?

Lösung

You may use XStream to transform your Entity[Implicitly Serializable] to XML & to de-serialize back to object. It may not be the effcient one, but fast & easy to implement.

I am successfully using the same process for a project.

Andere Tipps

ORM proxy stuff can be helped with using Gilead. http://noon.gilead.free.fr/gilead/

JPA provides a PersistenceUnitUtil class with an isLoaded() API that can be used to determine if a relationships is loaded.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top