I\'m using eclipse juno IDE I have Java application which have src folder. within the folder I have:
1) applicationContext.xml
2) persistence.xml
I a
Ok, I Solved this..
What i did is to put the persistence.xml file within the META-INF folder as vikdor and axtavt suggested. but in the application context i didn't import any file.. just wrote this
<bean id="JPA" class="pack.jpa.JPAQueries"/>
and its work!
It should be imported as follows:
<import resource="classpath:META-INF/persistence.xml"/>
assuming the persistence.xml is present in META-INF directory which is a top-level directory in one of your jars on the classpath.
Your attempt to use persistence.xml
as a Spring config makes absolutely no sense, because persistence.xml
is not a Spring config.
If you want to use JPA with Spring, you need to put persistence.xml
into META-INF
folder inside your source folder, and declare LocalContainerEntityManagerFactory
in applicationContext.xml
:
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name = "persistenceUnitName" value = "MyJPA" />
</bean>
Then you can inject EntityManager
into your Spring bean using @PersistenceContext
:
@PersistenceContext
private EntityManager em;
See also: