Announcement Announcement Module
No announcement yet.
Extend PersistenceBrokerDaoSupport or PersistenceBrokerTempl Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Extend PersistenceBrokerDaoSupport or PersistenceBrokerTempl

    In the PetClinic example, the DAO's extended PersistenceBrokerDaoSupport. Some developers in our organization extend PersistenceBrokerTemplate instead so they don't need to call getPersistenceBrokerTemplate() on every database call.

    Is there any harm in implementing PersistenceBrokerTemplate instead of PersistenceBrokerDaoSupport?


  • #2
    No, there shouldn't be any harm in extending PersistenceBrokerTemplate itself. It's just a bit questionable in terms of the object model: *Is* your DAO a PersistenceBrokerTemplate (which would mean extending it) or does it just *use* a PersistenceBrokerTemplate (which would mean delegation - the PersistenceBrokerDaoSupport model)? I would strongly argue for the latter.

    One disadvantage beyond the clarity of the object model is the visibility of methods: If all your DAOs extend PersistenceBrokerTemplate, all your DAOs will show all of PersistenceBrokerTemplate's public methods - which shouldn't really be public at the DAO level. Of course, you can conceal those with a proper DAO interface, but they're nevertheless gonna be public in the DAO implementation class.

    Of course, those thoughts analogously apply to HibernateTemplate / HibernateDaoSupport, JdoTemplate / JdoDaoSupport, etc.



    On the occasion: The upcoming Spring 1.1.4 (to be released by the end of this week) features two improvements in the OJB area.

    First, a convenient getObjectById(entityClass, idValue) method on PersistenceBrokerTemplate (for single primary keys).

    Second, a TransactionAwareDataSourceConnectionFactory (subclass of LocalDataSourceConnectionFactory), allowing OJB operations to participate in Spring-managed transaction timeouts and also to participate in a local transaction strategy other than PersistenceBrokerTransactionManager (for example, DataSourceTransactionManager or HibernateTransactionManager).


    • #3
      Thanks for the new features. We can really use the getObjectById one!

      Also thanks for the info on the template/daosupport.