Announcement Announcement Module
No announcement yet.
roo and transactions. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • roo and transactions.


    Im doing a project with roo and google app engine.

    For some reason my unit tests failed with errors, and now I managed to find out why: the utility methods of the entities.

    My entities have the roo generated aspects, but the utility methods does not seem to work correctly.

    problem 1:
    the persist() method has @Transactional(propagation = Propagation.REQUIRES_NEW) annotation. this commits the current transaction, creates a new one, and commits it. the problem with this that if this method is called from a context where there already is a transaction, the outer transaction will finish with an error. And also all lazy reads after the commit are going to end with an error.

    problem 2:
    Spring documentation says that static methods can not be made to work as a transaction with the @Transactional annotation. and my tests confirmed this. Why does roo generate static transactional methods then?

    problem 3:
    Even if the static methods can work as a transaction, the query methods of an entity will cause problems with certain frameworks. this was generated by roo:
        public static List<TestEntity> TestEntity.findAllTestEntitys() {
            return entityManager().createQuery("select o from TestEntity o").getResultList();
    With certain JPA frameworks (such as DataNucleus), this will cause an error. Since the transaction ends after returning from the method, and DataNucleus always lazy loads the collections, if someone tries to access the result list of this method, will get an exception (ObjectManager closed).

    Is there a normal workaround for these problems? Am I missing something? Or i should just not use these entity utility methods?