I started with Akka for java a few days ago and successfully created
the first flow of messages.
right now, I need to find out how to access plays JPA from a new
thread, as I an exception like this
when trying to access JPA in an actor:
play.exceptions.JPAException: The JPA context is not initialized. JPA
Entity Manager automatically start when one or more classes annotated
with the @javax.persistence.Entity annotation are found in the
application.
at play.db.jpa.JPA.get(JPA.java:22)
at play.db.jpa.JPA.em(JPA.java:51)
at play.db.jpa.JPQL.em(JPQL.java:16)
at play.db.jpa.JPQL.count(JPQL.java:20)
at models.Balance.count(Balance.java)
at actors.GenericImportDispatcher.onReceive(GenericImportDispatcher.java:80)
at akka.actor.UntypedActor$$anonfun$receive$1.apply(UntypedActor.scala:68)
at akka.actor.UntypedActor$$anonfun$receive$1.apply(UntypedActor.scala:67)
at akka.actor.Actor$class.apply(Actor.scala:449)
at akka.actor.UntypedActor.apply(UntypedActor.scala:63)
at akka.actor.LocalActorRef.invoke(ActorRef.scala:836)
at akka.dispatch.MessageInvocation.invoke(MessageHandling.scala:26)
at akka.dispatch.ExecutableMailbox$class.processMailbox(ExecutorBasedEventDrivenDispatcher.scala:215)
at akka.dispatch.ExecutorBasedEventDrivenDispatcher$$anon$5.processMailbox(ExecutorBasedEventDrivenDispatcher.scala:125)
at akka.dispatch.ExecutableMailbox$class.run(ExecutorBasedEventDrivenDispatcher.scala:188)
at akka.dispatch.ExecutorBasedEventDrivenDispatcher$$anon$5.run(ExecutorBasedEventDrivenDispatcher.scala:125)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
at akka.dispatch.MonitorableThread.run(ThreadPoolBuilder.scala:182)
Any help appreciated.
thanks,
dominik
--
Dominik Dorn
http://dominikdorn.com
http://twitter.com/domdorn
Skripten, Mitschriften, Lernunterlagen, etc. findest Du auf Study
Guru: http://www.studyguru.eu !
--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.
The JPA Plugin is already started, but it only attaches to a
web-request or a Job, but not a thread created
by Akka.
my current workaround is to manually do the job of the JPA Plugin in
my actor....
I'm doing it like this right now (which will give me some performance penalties
and it's quite a hack imho ):
public class SomeActor extends UntypedActor {
public void onReceive(Object message){
// checks for other messages
// ...
else if(message instanceof ProfessorStub)
{
try{ // wrapping everything around a try catch
if(JPA.local.get() == null)
{
JPA.local.set(new JPA());
JPA.local.get().entityManager = JPA.newEntityManager();
}
Balance.count(); // sample code that uses JPA
}
finally {
JPA.local.get().entityManager.close();
JPA.local.remove();
}
return;
}
}
}
JPAPlugin.startTX(true) //true for read-only transaction
...code
JPAPlugin.closeTX(false)//false for don't roll backtransaction
have you found a solution for this?