Results 1 to 8 of 8

Thread: Help me with Hibernate/Spring and multiple databases

  1. #1
    Join Date
    Jan 2005
    Location
    Sofia, Bulgaria
    Posts
    38

    Default Help me with Hibernate/Spring and multiple databases

    Hi again,
    I already post similar question, but have no answer. :cry:

    I am wondering how it might be possible to work with multiple databases at the same time with Hibernate and Spring? I have a scenario with multiple 5 different databases (Oracle on different platforms). AFAIK, this would require 5 SessionFactories(each one configured for respective database), then maintaining 5 Hibernate sessions in my application.

    However, while each individual object can be guaranteed to be persisted in either one database or the other, the domain object model is split across 2 to 3 databases (part is data shared with legacy systems). This means we will be trying to load object **graphs** which span databases - The mappings dont allow objects to be mapped to Tables in different databases, and I can't readily see how we could do this directly in Hibernate. I think Spring will help, but don't know how.

    We had Some discussion about possibly front-ending the databases with third party software, and this is an option but this has performance drawbacks in our specific case.

    Has anybody acheived the same end result in some other way, or have any ideas, patterns or suggestions on how it might be possible (no matter how daft!)?
    Rostislav Georgiev

  2. #2
    Join Date
    Aug 2004
    Location
    Vrhnika, Slovenia
    Posts
    133

    Default

    Hmm ... looking a lot through Hibernate source code I highly doubt that achieving something similar easily is impossible . You could possibly hack some ClassPersister classes for you mapping classes. But you probably loose all the 'beauty' that Hibernate brings you.

    >I think Spring will help, but don't know how
    I think Spring can't help you here. Spring provides nice and clean transaction handling of Hibernate's Session, DAO and template exposure, ... , but as far as object graph loading is concerned, it all depends on Hibernate API.

    I had similar request. I then wrote a small persistant library. Now I would look for different solution - maybe ' front-ending the databases with third party software'.

  3. #3
    Join Date
    Nov 2004
    Posts
    21

    Default It may be possible..

    With the C-JDBC project.. Thats designed to present a single virtual database across multiple backend systems.. I have never used it myself, but some people have reported success with it.

    You can use it for "database level-raid", or for just mapping different systems together..

  4. #4
    Join Date
    Oct 2004
    Location
    Amsterdam, The Netherlands
    Posts
    28

    Default

    You could make your own CRUD layer you can use from your business logic layer with just Create, read, update and delete operations to the right database for every class you're mapping.

    Might not be the most interesting work to do :-).

  5. #5
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    Hi.

    There is no straight answer to you question. However I can tell you that you should search a solution inside an application server or at the db level.
    I know that oracle allows all kind of distributed scenarios so I think it would be possible to have all the databases connected by oracle and you would talk only with one session factory.
    A second alternative would be to use an application server (which has anyway the distributed transaction support). This way you can talk with 5 session factories and all the transaction will be delegated to the app server. However loading the objects from different databases is a 'fancy' problem and I don't know how exactly to handle it - Spring anyways doesn't has much to do with it as it's an IoC container and not an O/RM solution.

    Try the HB forums for advice - for sure there is some tool out there that takes care of this (at least a commercial one).
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  6. #6
    Join Date
    Aug 2004
    Location
    Vrhnika, Slovenia
    Posts
    133

  7. #7
    Join Date
    Mar 2010
    Posts
    1

    Default Multiple Database with Spring and Hibernate Annotation

    Hello Friends,

    I'm new to Spring as well as Hibernate annotaion.

    Initially i had single database with two tables user and user_group.
    I had single session factory, datasouce and hibernateDaoSupport.
    And application is working fine.

    My requirement has been modified as follows

    1. Now i have two databases, one database has user data and other has user_group
    2. How do i configure two databases with spring with hibernate Annotation?
    3 What all changes to be done to achieve this?

  8. #8

    Default

    Hibernate Shards was meant to solve this problem.
    look at - https://www.hibernate.org/414.html
    Though it show in beta right now.
    -Amit

Similar Threads

  1. JUnit tests - Support multiple databases
    By ejhernand3z in forum Data
    Replies: 5
    Last Post: Oct 22nd, 2008, 02:41 PM
  2. Replies: 6
    Last Post: Mar 18th, 2006, 05:42 PM
  3. Replies: 1
    Last Post: Feb 16th, 2005, 01:56 AM
  4. Replies: 2
    Last Post: Nov 12th, 2004, 05:23 AM
  5. multiple databases query (with a twist)
    By jamesni in forum Data
    Replies: 0
    Last Post: Sep 7th, 2004, 06:04 AM

Posting Permissions

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