Hibernate multiple databases

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Hibernate multiple databases

nquirynen
Hi,

For our current project we have the need to be able to connect to
multiple databases using Hibernate.
I have seen the blog post of Taha
(http://tawus.wordpress.com/2012/03/03/tapestry-hibernate-multiple-databases/)
and was wondering if there exists a library based on this or similar
that I can use as is? Else I will have to investigate in creating one
myself.

Greetings Nathan

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Hibernate multiple databases

Antal van Kalleveen
Hi Nathan,

I've written a module which has support for multiple databases through Hibernate. It's roughly based on Taha's implementation.
Besides that it contains a lot more usefull components ;)

See: https://github.com/intercommit/Weaves

Regards,
 Antal



---- OriginalMessage ----

>From: "Nathan Quirynen" <[hidden email]>
>To: "Tapestry users" <[hidden email]>
>Sent: Mon, Oct 13, 2014, 14:33
>Subject: Hibernate multiple databases
>
>Hi,
>
>For our current project we have the need to be able to connect to
>multiple databases using Hibernate.
>I have seen the blog post of Taha
>(http://tawus.wordpress.com/2012/03/03/tapestry-hibernate-multiple-databases/)
>and was wondering if there exists a library based on this or similar
>that I can use as is? Else I will have to investigate in creating one
>myself.
>
>Greetings Nathan
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Hibernate multiple databases

nquirynen
Hey Antal,

Thanks for sharing your library! Will surely help me.
Is there any place I can find how to make use of it (documentation or
examples)?

Thanks,
Nathan

On 14/10/14 09:26, Antal van Kalleveen wrote:

> Hi Nathan,
>
> I've written a module which has support for multiple databases through Hibernate. It's roughly based on Taha's implementation.
> Besides that it contains a lot more usefull components ;)
>
> See: https://github.com/intercommit/Weaves
>
> Regards,
>  Antal
>
>
>
> ---- OriginalMessage ----
>> From: "Nathan Quirynen" <[hidden email]>
>> To: "Tapestry users" <[hidden email]>
>> Sent: Mon, Oct 13, 2014, 14:33
>> Subject: Hibernate multiple databases
>>
>> Hi,
>>
>> For our current project we have the need to be able to connect to
>> multiple databases using Hibernate.
>> I have seen the blog post of Taha
>> (http://tawus.wordpress.com/2012/03/03/tapestry-hibernate-multiple-databases/)
>> and was wondering if there exists a library based on this or similar
>> that I can use as is? Else I will have to investigate in creating one
>> myself.
>>
>> Greetings Nathan
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Re: Hibernate multiple databases

Antal van Kalleveen
In reply to this post by nquirynen
Hi,

Unfortunately i dont really have any documentation other than the sources on github ;)

The basic setup is to contribute a 'SessionFactoryConfiguration' to 'SessionFactorySource' like this : in the 'AppModule'

---------------------------------------------------------------------
    /*
    * contribute at least one default factory based on hibernate.cfg.xml found on the classpath..
    */
    public void contributeSessionFactorySource(MappedConfiguration<String,SessionFactoryConfiguration> configuration) {
   
    try {
   
                   final SessionFactoryConfiguration defaultConfig = new SessionFactoryConfiguration(new String[] {"nl.intercommit.weaves.demo.entities.factory1"},new File(
                                   this.getClass().getResource("/hibernate.cfg.xml").toURI()));
                   // get in as first!
                   configuration.add("T5SessionFactory",defaultConfig);
                   
                  final SessionFactoryConfiguration anotherConfig = new SessionFactoryConfiguration(new String[] {"nl.intercommit.weaves.demo.entities.factory2"},new File(
                                  this.getClass().getResource("/someconfig.cfg.xml").toURI()));
                   // and another one.
                   configuration.add("Otherfactory",anotherConfig);
    } catch (URISyntaxException use) {
    throw new TapestryException("could not initialize session factories",use);
    }
   
    }
---------------------------------------------------------------------

Then in your 'page' code, create a Hibernate Session from the @Injected 'HibernateMultiSessionManager'


---------------------------------------------------------------------

        @Inject
        private HibernateMultiSessionManager manager;
       
        private Session session1;
       
        private Session session2;
       
        private void onActivate() {
               
                session1 = manager.getSession(SomeEntity.class);
                session2 = manager.getSession("Otherfactory");
        }

---------------------------------------------------------------------

this will create 2 different session to 2 different Databases, assuming the entity 'SomeEntity' does not belong to the 'Otherfactory'


regards,
  Antal




---- OriginalMessage ----

>From: "Nathan Quirynen" <[hidden email]>
>To: "Tapestry users" <[hidden email]>
>Sent: Tue, Oct 21, 2014, 11:50
>Subject: Re: Hibernate multiple databases
>
>Hey Antal,
>
>Thanks for sharing your library! Will surely help me.
>Is there any place I can find how to make use of it (documentation or
>examples)?
>
>Thanks,
>Nathan
>
>On 14/10/14 09:26, Antal van Kalleveen wrote:
>> Hi Nathan,
>>
>> I've written a module which has support for multiple databases through Hibernate. It's roughly based on Taha's implementation.
>> Besides that it contains a lot more usefull components ;)
>>
>> See: https://github.com/intercommit/Weaves
>>
>> Regards,
>>  Antal
>>
>>
>>
>> ---- OriginalMessage ----
>>> From: "Nathan Quirynen" <[hidden email]>
>>> To: "Tapestry users" <[hidden email]>
>>> Sent: Mon, Oct 13, 2014, 14:33
>>> Subject: Hibernate multiple databases
>>>
>>> Hi,
>>>
>>> For our current project we have the need to be able to connect to
>>> multiple databases using Hibernate.
>>> I have seen the blog post of Taha
>>> (http://tawus.wordpress.com/2012/03/03/tapestry-hibernate-multiple-databases/)
>>> and was wondering if there exists a library based on this or similar
>>> that I can use as is? Else I will have to investigate in creating one
>>> myself.
>>>
>>> Greetings Nathan
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: [hidden email]
>For additional commands, e-mail: [hidden email]
>
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]