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>

Comments

Comments below were made on a legacy Blog, before move to current Blog (February 2019)

krla:

Thank you. You solved my problem ;)

28 May 2008, 08:58:00
m4rkuz:

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

10 Sep 2008, 03:38:00
Anonymous:

Perfect! Thanks :)

/bitte

12 Nov 2008, 12:18:00
Anonymous:

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

11 Jan 2009, 15:51:00
Mark:

This solved it. Thanks

25 Mar 2009, 10:53:00
comment author
Timothy Wonil Lee:

thanks for this!

6 Aug 2009, 07:52:00
Anonymous:

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

5 Oct 2009, 10:38:00
Anonymous:

You da man! Thanks for posting this!

30 Dec 2009, 03:07:00
Anonymous:

thank you man!

12 Feb 2010, 18:32:00
jalejo:

Thank's a lot!!!
Nice solution

23 Apr 2010, 01:31:00
comment author
Anil Samuel:

life saver !!

12 May 2010, 01:03:00
gdadadadasd:

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

26 May 2011, 00:30:00
Anonymous:

Thanks for the solution!

30 Jun 2011, 15:49:00
Reigo:

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

25 Nov 2011, 20:09:00
Anonymous:

Solved my problem. Thanks for the post.

29 Jan 2012, 21:36:00
Anonymous:

thank you, Sir!

29 Feb 2012, 22:39:00
hugo p:

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

15 Nov 2012, 09:47:00
Anonymous:

Big Thank you, you rock !
modjo2010

28 Jan 2014, 14:14:00
Creative Commons License

Unless otherwise specified, all content is licensed under Creative Commons by Attribution 3.0 (CC-BY).

Externally linked images and content are not included and are licensed and copyrighted separately.