How to mark persistence block as default in JPA (hibernate)?
I have read several threads while setting one of the n default persistence units in JPA. But the use of hibernate.default_schema seems to be undefined.
However, I want to achieve the following.
- Default
<persistence-unit name="myMainPU"> ... </persistence-unit>
- Do you have one or more additional
<persistence-unit name="auxilliaryPU"> ... </persistence-unit>
- I do not want to comment on EntityManagers annuities with name attribute. For example. not the same
@Persistence(unitName="myMainPU")
for the default save unit. It should be just like that@Persistence
. - I want to annotate my auxiliary PUs with the unitName attribute. For example.
@Persistence(unitName="auxilliaryPU")
How is this achieved? I am using Hibernate 4+ and can make my own decision as well.
Thank.
+3
source to share
2 answers
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>
0
source to share