borjab
borjab

Reputation: 11665

JPA equivalent command to Hibernate.initialize

I have a Lazy collection that I want to initialize at will in my service/controller. At this moment I can do:

Hibernate.initialize( myEntity.getListOfThings() );

This command is hibernate dependent and does not make the implementation of JPA transparent. Is there a JPA elegant way of doing this?

Upvotes: 5

Views: 4722

Answers (1)

Master Slave
Master Slave

Reputation: 28569

No, there's no JPA equivalent. You can learn if the object is loaded and than use one of the two options, either accessing the properties while the object is still attached to persistence context, what I typically see is calling size, just for the sake of initializing the collection

myEntity.getListOfThings().size();

or use a query for initialization.

Upvotes: 3

Related Questions