feder
feder

Reputation: 2058

How to mark a persistence-unit as default in JPA (hibernate)?

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.

How does one achive that? I use Hibernate 4+ and could also accept a proprietary solution.

Thanks.

Upvotes: 4

Views: 2667

Answers (3)

michdraft lord
michdraft lord

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

Dario Cimafonte
Dario Cimafonte

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

uaiHebert
uaiHebert

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

Related Questions