Results 1 to 5 of 5

Thread: Problem with differnt implementations of DAO

  1. #1
    Join Date
    Aug 2007
    Posts
    1

    Unhappy 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. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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.
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3
    Join Date
    Jul 2007
    Location
    Juan Les Pins, France
    Posts
    42

    Default

    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. #4

    Default

    Or just look at the Spring-provided Petclinic sample ...
    -Andy
    DataNucleus - Standardised persistence, multiple datastores

  5. #5
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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?
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •