bertra
May 27th, 2009, 07:52 AM
hi,
I have a wicket application with JPA(Hibernate) as orm, using Spring to wire the the EntityManger into DAO objects. It all works fine so far (the spring config is taken from the wicket wiki). But now i would like to use the same application with different databases. in the moment, i have a persistence unit defined for each database and use maven profiles to build different wars, the difference being only the persistence unit to use in the config.
as the number of databases grows, this becomes ugly, as i have to define more and profiles and worst, have to deploy the same app many times, wasting memory.
what i have is a url along the lines:
/myApps/alpha/xxx
/myApps/beta/xxx
...
where alpha and beta and so on describe the database/persistence unit to use.
i use a OpenEIVF:
web.xml
<filter>
<filter-name>openEntityManagerInViewFilter</filter-name>
<filter-class>
org.springframework.orm.jpa.support.OpenEntityMana gerInViewFilter
</filter-class>
</filter>
and define the beans in the applicationContext.xml:
<tx:annotation-driven transaction-manager="txManager"
proxy-target-class="true"/>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFact oryBean">
<property name="persistenceUnitName" value="alpha" />
</bean>
<bean id="txManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
How can i get rid of the static property persistenceUnitName and define that for every request?
I read through the sections in the doc and the JavaDoc of these classes, but so far without any hint.
is this at all possible? As far as i understand, the LocalEntityManagerFactoryBean is created at startup ..
any hints would be welcomed
thx, bert
I have a wicket application with JPA(Hibernate) as orm, using Spring to wire the the EntityManger into DAO objects. It all works fine so far (the spring config is taken from the wicket wiki). But now i would like to use the same application with different databases. in the moment, i have a persistence unit defined for each database and use maven profiles to build different wars, the difference being only the persistence unit to use in the config.
as the number of databases grows, this becomes ugly, as i have to define more and profiles and worst, have to deploy the same app many times, wasting memory.
what i have is a url along the lines:
/myApps/alpha/xxx
/myApps/beta/xxx
...
where alpha and beta and so on describe the database/persistence unit to use.
i use a OpenEIVF:
web.xml
<filter>
<filter-name>openEntityManagerInViewFilter</filter-name>
<filter-class>
org.springframework.orm.jpa.support.OpenEntityMana gerInViewFilter
</filter-class>
</filter>
and define the beans in the applicationContext.xml:
<tx:annotation-driven transaction-manager="txManager"
proxy-target-class="true"/>
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalEntityManagerFact oryBean">
<property name="persistenceUnitName" value="alpha" />
</bean>
<bean id="txManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
How can i get rid of the static property persistenceUnitName and define that for every request?
I read through the sections in the doc and the JavaDoc of these classes, but so far without any hint.
is this at all possible? As far as i understand, the LocalEntityManagerFactoryBean is created at startup ..
any hints would be welcomed
thx, bert