Spring + JPA – Example with Exception/Error – Fixing


In this post ,I have given a  simple example on how to use JPA in Spring Framework.
You can find the source code of the below example in my Github link here.

I have considered a MusicStore example, where i just get the list of Songs from the database.


Framework: Spring
Persistence API : JPA 2.0
Build : Maven
Database : MySQL
JPA Provider : Hibernate-JPA Provider

While I was working on integrating JPA into Spring , I felt that, the most important part to concentrate on , is the CONFIGURATION area.

So,let’s get started with application-context.xml and persistence.xml


  • DIFFERENCE BETWEEN <context:annotation-config> AND <context:component-scan base-package=”…..”>

<context:annotation-config> -Enables the usage of JPA annotations(@Service, @Component, @Repository, @Controller  and etc.,)
<context:component-scan base-package=”…..”> – This component-scan tag also enables the usage of JPA annotations.

Then the difference ???

(i) annotation-config —> enables the usage of JPA annotations , only in…

View original post 424 more words