[RuntimeException: No EntityManager bound to this thread. Try to annotate your action method with @play.db.jpa.Transactional]

Root cause :- I was trying to access an Entity object from Play framework Controller.

Solution :
First I tried to annotate the method that calls the JPA object with 

@play.db.jpa.Transactional

But It did n't help, finally i got the issue resolved by using the following piece of code.



 private static void populateList (String company, String uid) {
        
     final String dbName = company;
     final String Uid = uid;
     try {
         JPA.withTransaction(company, true,
                 new play.libs.F.Function0() {
                     @Override
                     public Void apply() throws Throwable {
                         List bhaList = BHA.findByUidWell(dbName, Uid);
                         System.out.println(bhaList.size());
                         return null;
                     }
                 });
     } catch (Throwable throwable) {
         Logger.error("Error: ", throwable);
     }
        
    }

Hope this helps :)

No comments:

 Python Basics How to check the version of Python interpreter mac terminal

Popular in last 30 days