java - How can I define multiple sessionfactory instances in Spring? -


I would like to have multiple hibernate session functions in a spring application, except for all datasource except with the same configuration. Ideally, I will receive a specific session session by name. I need to be able to do this on the basis of runtime state, and it is not possible to determine which session factories will need me at the application startup time. Actually, I need a sessionfinder template or something like that.

Is this possible? How can you do it?

You can define a bean bean and use the bean heritage. This means that you will have a definition of a bean that acts as a template and you can have multi-seminars, which make a copy of the qualities set by the parent bean.

Here's an example:

  & lt; Bean id = "Abstract Season Factor" abstract = "true" class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean" & gt; & Lt; Property Name = "Mapping Resources" & gt; & Lt; List & gt; & Lt; Price & gt; Product.hbm.xml & lt; / Pricing & gt; & Lt; / List & gt; & Lt; / Property & gt; & Lt; Property Name = "Hibernate Properties" & gt; & Lt; Price & gt; Hibernate.dialect = org.hibernate.dialect.HSQLDialect & lt; / Value & gt; & Lt; / Property & gt; & Lt; / Bean & gt; & Lt; Bean id = "mySessionFactory" parent = "abstractSessionFactory" & gt; & Lt; Property Name = "Data Source" Riff = "MyData Source" /> ... & lt; / Bean & gt; & Lt; Bean id = "mySessionFactory2" parent = "Abstract Factory" & gt; & Lt; Property Name = "Data Source" Riff = "Moodyada Source 2" /> ... & lt; / Bean & gt; By using the feature 'Abstract' you ensure that bean will not be used immediately and will be used only as a template. 

More info here:


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -