Thursday, 15 September 2011

jpa 2.0 - How to get a detached object from JPA -



jpa 2.0 - How to get a detached object from JPA -

in application need objects fetched in detached mode (fetched find api). i'm wondering if there way inquire detached object jpa provider , save phone call detach() api. in additional expect object created in such mode less expensive since jpa provider doesn't need add together entity manager context. there way accomplish jpa apis? there way accomplish such functionality query results?

specifically i'm using eclipse link if there specific way implementation helpful well.

you can fetch detached entity without phone call detach() if fetch outside transaction. if not using container-managed transactions, it's trivial, not start transaction.

if using cmt, have create sure requesting object not transaction-enabled ejb:

if in ejb, suspend transaction annotating appropriate method with:@transactionattribute(transactionattributetype.not_supported),

or

call entitymanager pojo. dont have phone call directly, impotrant query result end in non-ejb object.

afaik, there no performance gain expected, since query result set in current persistence context, shortlived may be.

edit: there possibility detached objects not depend on transaction demarcations: jpa constructor expressions:

list<dto> dtos = em.createquery("select new com.example.dto( o.title, o.version) entity o").getresultlist();

the constructed type must have constructor relevant attributes. objects in list, entities or not, created detached. there little overhead of instantiating new object.

jpa jpa-2.0 eclipselink

No comments:

Post a Comment