Results 1 to 6 of 6

Thread: JDBC Abstraction and Spring

  1. #1
    Join Date
    Nov 2004
    Posts
    159

    Default 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?

    Thanks!

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    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...
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

  3. #3
    Join Date
    Nov 2004
    Posts
    159

    Default

    Thanks Rod.

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

    Thanks again!

  4. #4
    Join Date
    Nov 2004
    Posts
    159

    Default

    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?

    Thanks!

  5. #5
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    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).

    Juergen

  6. #6
    Join Date
    Nov 2004
    Posts
    159

    Default

    Thanks Juergen. I'll try this out.

Similar Threads

  1. Newbie Question - The Ideal Spring Solution
    By conorp in forum Architecture
    Replies: 3
    Last Post: Aug 23rd, 2005, 03:22 AM
  2. Replies: 5
    Last Post: Mar 14th, 2005, 10:18 AM
  3. Utilize Spring's JDBC Framework or iBATIS
    By jaybytez in forum Data
    Replies: 2
    Last Post: Mar 11th, 2005, 06:24 PM
  4. Why Spring
    By spring04 in forum Architecture
    Replies: 10
    Last Post: Nov 21st, 2004, 12:34 PM

Posting Permissions

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