Lazy collection of JPA detach entity in script task

Hi,

Is there a generic way to tag some script task (groovy, …) to open a jpa session to avoid Lazy exception when accessing a lazy collection of a JPA detach entity ?

With some listener ? …

My goal is to avoid to load every collections of every entities in process input variables before launching it. Is there best pratice for that ?

Thx

no one do that ? i’m sur some of you having facing the same issues, questions, …

any help, please ? up up

please explain to me if my question is wrong ?

Hi Jerome,

It’s certainly not wrong, but a little unspecific.

  1. Can you please describe which Camunda and JPA features you intend to use?
  2. Can you give example code that raises the lazy initialization exception?
  3. Can you describe what would be the correct JPA usage if you were coding this in plain Java (no Camunda, no Groovy)?

These things are not clear to me, especially since I don’t know JPA that well.

Best regards,
Thorben

Hi,

I just want to use an input variable, name “operator” of Operator class (JPA entity), with a lazy collection of Suppliers.
In the processing, i have a simple script task counting the suppliers.

When the groovy script is launched, i have a “Lazy exception”

Caused by: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.camunda.demo.springboot.model.Operator.suppliers, could not initialize proxy - no Session
at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:587)
at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:204)
at org.hibernate.collection.internal.AbstractPersistentCollection.readSize(AbstractPersistentCollection.java:148)
at org.hibernate.collection.internal.PersistentBag.size(PersistentBag.java:261)
at java_util_List$size.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117)
at Script1.run(Script1.groovy:1)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317)
... 126 more

I’m wondering if there is a way to open a JPA session in the script task to avoid this error ?