Announcement Announcement Module
Collapse
No announcement yet.
Spring/JDO(Kodo) problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring/JDO(Kodo) problem

    I am currently testing Kodo JDO implementation with Spring framework, I implemented a DAO class, which extends JdoDaoSupport.

    The problem is each time when I try to use getJdoTemplate().find(...) the result is unusable, because the persistent manager is closed before the results are returned, and JDO would not allow access to persistent objects when persistent manager is closed.

    I know in web environment, there are options like OpenPersistenceManagerInViewInterceptor/OpenPersistenceManagerInViewFilter, but I am not using JDO in web environment (and I need the code to be testable using junit in any case).

    Anyone know whether there is a way to fix this problem, or Spring framework is not meant to work with Kodo JDO?

  • #2
    It sounds like you are not using your dao inside a service object of some sort which is itself transactinal. This is the normal preferred architecture. If you wrap your business layer objects with declarative transactions, using JdoTransactionManager, then a PersistenceManager will be created and bound to the thread and synchronized to the transaction, when the tx is actually created. That same PM wil then be used inside all the code wrapped by the transaction.

    Comment


    • #3
      Spring + JDO Sample App

      You can find a link to a sample Spring + Kodo JDO application at www.solarmetric.com. It's a web application, but it shows a couple patterns of how you can use JDO with Spring that apply to other types of applications, too.

      Note also that Kodo 3.2 (now at release candidate 1 stage, RC1) supports "detach on PM close". See http://www.solarmetric.com/Software/...ach_auto_close for more details. This will allow you to access the objects after the PM is closed. Because they will be detached, however, lazy loading will not work (any fields that were not in your default fetch group or initial fetch configuration won't be accessible). Generally we recommend doing what Colin recommended above.
      Thanks,
      Greg

      Comment


      • #4
        What about the "NontransactionalRead" option?

        Me too had seen this error before and was annoyed that the PM was so eagerly closed by either JdoTemplate or JdoTransactionManager. In my case, the application is a swing fat client that need to keep a PM open for the entire application lifetime. The "NontransactionalRead" option is enabled to avoid opening transactions all the time, as shown in the Kodo examples. However, the "NontransactionalRead" seems do not work with closed PM. It is a serious drawback for the Spring JDO support.

        Maybe I missed something, IMHO, the JdoTransactionManager should only manage Transactions and leave the PM management to the application. For example, a boolean property "closePMAfterCompletion" can be added to the JdoTransactionManager.

        Comment


        • #5
          Guys, thanks for the quick response.

          In my test application I actually use ' JdoTransactionManager' and declarative transactions, but I only mark the methods which have update operations as transactional.

          Most methods of my DAO class only do queries, like find a user by name, does it mean that even pure query methods have to be marked as transactional and I need either make the objects transient or detached before I return them? Wouldn't that be sort of wired to mark the methods transactional just because I use JDO?

          Comment

          Working...
          X