Play-java/Hibernate: No EntityManager when annotated with Transactional

662 views
Skip to first unread message

Johan Dahlberg

unread,
Apr 7, 2015, 3:40:51 AM4/7/15
to play-fr...@googlegroups.com
I get this error even though I annotate the method as follows:

[play-akka.actor.default-dispatcher-31] ERROR be.objectify.deadbolt.java.utils.RequestUtils - Error getting subject: No EntityManager bound to this thread. Try to annotate your action method with @play.db.jpa.Transactional
java.lang.RuntimeException: No EntityManager bound to this thread. Try to annotate your action method with @play.db.jpa.Transactional
at play.db.jpa.JPA.em(JPA.java:51)
at dao.AbstractDAO.<init>(AbstractDAO.java:28)
at dao.UserDAO.<init>(UserDAO.java:16)
at models.User.authenticate(User.java:141)
at controllers.Application.getLoggedOnUser(Application.java:45)
at auth.MyDeadBoltHandler$1.apply(MyDeadBoltHandler.java:36)
at auth.MyDeadBoltHandler$1.apply(MyDeadBoltHandler.java:33)
at play.core.j.FPromiseHelper$$anonfun$promise$2.apply(FPromiseHelper.scala:36)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24)
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24)
at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:40)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:393)
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)



@Transactional
@Pattern(value = "systemadmin.remove", content = "Remove")
public static Result remove(Long unitId) {}

I had this error before but that was when Transactional hade been placed after Pattern by accident. It works on all other places, is it something with Transactional that I am missing? the reference to deadbolt in the first row in the error message suggests that the error is caused in the Pattern annotation.

Johan Dahlberg

unread,
Apr 8, 2015, 10:25:17 AM4/8/15
to play-fr...@googlegroups.com
Am I the only one with this problem?

/Johan

Matthias Kurz

unread,
Apr 9, 2015, 4:53:10 AM4/9/15
to play-fr...@googlegroups.com
Hi Johan,

If you are using deadbolt-java v2.3.3 than it's a bug in deadbolt you are facing. I reported the issue yesterday: https://github.com/schaloner/deadbolt-2-java/issues/7
The maintainer of the deadbolt project is working on a fix already so hopefully this will be resolved soon.
For now you can downgrade to v2.3.2 and to resolve the bug.

Regards,
Matthias

Johan Dahlberg

unread,
Apr 9, 2015, 5:58:33 AM4/9/15
to play-fr...@googlegroups.com
Yes, I have seen that issue already. I am currently using 2.3.2 and it's only one a few places that this error occurs. But maybe his solution will get rid of those as well.

/Johan

--
You received this message because you are subscribed to a topic in the Google Groups "play-framework" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/play-framework/sS__wS1L-cw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to play-framewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Steve Chaloner

unread,
Apr 9, 2015, 7:35:36 AM4/9/15
to play-fr...@googlegroups.com
The proposed solution is to copy and tweak the play.db.jpa.JPA class, so the entity manager is removed from the context on the failure or redemption of the controller action.  The only change required will be - assuming this works out - is adding a new dependency and changing your @Transactional annotations to @AsyncTransactional. 

You can see the proposed solution at this gist: https://gist.github.com/schaloner/082108f5f0dcc76fd64b

Regards,
Steve

Johan Dahlberg

unread,
Apr 9, 2015, 8:01:42 AM4/9/15
to play-fr...@googlegroups.com
Thanks, I will keep an eye on that issue.

/Johan
Reply all
Reply to author
Forward
0 new messages