문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top