Announcement Announcement Module
No announcement yet.
Problem with differnt implementations of DAO Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with differnt implementations of DAO

    Hi All,

    I'm comparatively new to "Spring". I have a problem, like, in my application I need to perform all the read operations from DB should be done through SQL and all the data manipulation operation shoud be done through Hibernate. For this purpose I'm thinking about two different implementations for Dao Interface. One is a JDBC implementation and the other is Hibernate.

    Is this possible? can I inject 2 different implementations of an interface?
    Looking forward for your help .....

  • #2
    You can have two implementions, but it sounds like you just want one. If you are mandating that some operations use Hibernate and some use Jdbc you can do all this in the same DAO.


    • #3
      Alternatively, if you want an implementation based seperation; you can create two seperate interfaces; one for JDBC access and other for Hibernate access. Your implementations can extend JDBCDaoSupport and HibernateDaoSupport respectively. This will provide a clear seperation not only between implemetations but also between read-write data access.

      If the purpose is to restrict the read-only methods to perform any write operation, you can set up your transaction manager with read-only attribute for all the read-only methods. Any write operations performed within this method will throw a RuntimeException.

      There are different ways of achieving what you are trying to do; pick the one that fits best in your design.


      • #4
        I guess this basically all depends on the exact details of what you are trying to do. Any chance you can supply some more details?