Tuesday, 22 April 2008

No single default persistence unit defined

If you getting nowhere with this type of problem:

Using spring and jpa, and you get this error:

No single default persistence unit defined in {classpath*:META-INF/persistence.xml}

And you DO have a persistence.xml in your classpath.

Then the cause is simple.

You may have other persistence.xml files as well in your lib/jars.

Solution, add your persistenceUnitName to entityManager bean.


<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="persistenceUnitName" value="blahblahYourName" />


which matches the one in your persistence.xml


<persistence-unit name="blahblahYourName">

</persistence-unit>

19 comments:

Anonymous said...

Thank you. You solved my problem ;)

Unknown said...

you solve my problem...
I got it in a spring web flow app example

Anonymous said...

Perfect! Thanks :)

/bitte

Anonymous said...

Thanks!! This problem was driving me nuts... PB

Anonymous said...

This solved it. Thanks

Timothy Wonil Lee said...

thanks for this!

Anonymous said...

Thanks, this solved an issue I encountered some time ago as well!

Anonymous said...

You da man! Thanks for posting this!

Anonymous said...

thank you man!

jalejo said...

Thank's a lot!!!
Nice solution

Anil Samuel said...

life saver !!

Anonymous said...

Is it possible to have multiple persistence unit in one persistence.xml file?

sempervivo said...

Thank you very much. I learned something new today, thanks to you.

Anonymous said...

Thanks for the solution!

Anonymous said...

Solved my problem which only occured while trying to run the project with JRebel. Thanks!

Anonymous said...

Solved my problem. Thanks for the post.

Anonymous said...

thank you, Sir!

hugo p said...

Solved conflicts between multiple war on the same server.
Thank you !

Anonymous said...

Big Thank you, you rock !
modjo2010