Reputation: 2058
I read a few threads on setting a one out of n persistence-unit in JPA as default. But the usage of hibernate.default_schema seems to be vague.
However, I want to achieve the following.
<persistence-unit name="myMainPU"> ... </persistence-unit>
<persistence-unit name="auxilliaryPU"> ... </persistence-unit>
@Persistence(unitName="myMainPU")
for the default persistence unit. Should be simply like this @Persistence
.@Persistence(unitName="auxilliaryPU")
How does one achive that? I use Hibernate 4+ and could also accept a proprietary solution.
Thanks.
Upvotes: 4
Views: 2667
Reputation: 67
If you use wildfly as container, you can add the following property to persistence-unit which you consider as default. I assum other container may have such a property.
<property name="wildfly.jpa.default-unit" value="true" />
Upvotes: 0
Reputation: 1
If you're using Spring, try adding this before any other bean:
<bean id="org.springframework.context.annotation.internalPersistenceAnnotationProcessor" class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"
depends-on="myDefaultEntityManagerFactory, myAuxiliaryEntityManagerFactory, yetAnotherEntityManagerFactory">
<property name="defaultPersistenceUnitName" value="my-default-PU" />
</bean>
Upvotes: 0
Reputation: 1912
There is no such default option of "default pu".
What you could do is to use CDI and decide which PU you will use. I cannot see other way of doing it.
Upvotes: 2