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

  • JDBC Abstraction and Spring

    I just read the documentation for JDBC abstraction. I like the features like mapping the query results to an object.

    If i want to use both JDBC abstraction and Hibernate in my application, say for example, i want to use JDBC abstraction for queries and Hibernate for insert/update etc how should i do this?

    Do i need write a Dao that implements "findXXX" methods using JDBC abstraction and "insert/UpdateXXX" methods using Hibernate and then provide "business interface" say myProjectFacade that uses both in the same TRANSACTION???

    Could some one clarify this please?

    I read some posts that indicates that hibernate doesn't perform well for "queries" and performs well for "updates/inserts". Hence i'm thinking of using both to get the best of both worlds in my application.

    Any comments?

    Any sample code that uses both?


  • #2
    Yes, Spring can use both in the same transaction, even if you're not using JTA. It's a great feature of Spring's tx mgt.

    I read some posts that indicates that hibernate doesn't perform well for "queries" and performs well for "updates/inserts".
    HQL is actually pretty good for queries in my experience. It's normally things like set-based updates that make most sense for JDBC. Remember you can write queries in SQL if you want with Hibernate and put them in your Hibernate mapping file as named queries.

    Of course, while Spring takes care of tx mgt, you need to be sure that you're not invalidating Hibernate's transactional cache with your JDBC operations, or holding unflushed updates in Hibernate that JDBC can't yet see...


    • #3
      Thanks Rod.

      If i had to flush Hibernate cache often, won't it be a performance overhead?

      Thanks again!


      • #4
        Also in this scenario (of using both JDBC and Hibernate in the same txn), assuming that i'm flusing the hibernate cache, as required, JDBC can see the latest changes. But if i make changes using JDBC to the data store,how will hibernate detect those changes? Do we have any event notifications to hibernate cache???

        This could be the problem even when external application directly modified the datastore and hence the hibernate cache becomes invalid.

        How should i handle in this case?



        • #5
          You can invalidate specific objects in Hibernate's caches via Session's "evict" and SessionFactory's "evict", for the first-level cache and second-level cache, respectively. If you modify data via JDBC and you know that it could be cached by Hibernate, you'd need to explicitly evict the corresponding objects from the Hibernate cache(s).



          • #6
            Thanks Juergen. I'll try this out.