title: Spring with JPA pure approch
body: <p>I have a problem with Spring and JPA. Basically I try to use JPA with Spring with a pure approach, or better, without explicit references in the code to Spring framework with the exception of the @Transactional. So I wanted to know where wrong.
  My persistence.xml is:</p>
  
  <pre><code>&lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
               version="2.0"&gt;
      &lt;persistence-unit name="fb-persistence" transaction-type="RESOURCE_LOCAL"&gt;  
          &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
          &lt;class&gt;it.synclab.fb.jpa.entity.Plugin&lt;/class&gt;
          &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect"/&gt;
              &lt;!-- da utilizzare solo in caso di creazione dello schema &lt;property name="hibernate.hbm2ddl.auto" value="create-drop"/&gt;--&gt;
              &lt;property name="hibernate.connection.driver_class" value="oracle.jdbc.driver.OracleDriver"/&gt;  
              &lt;property name="hibernate.show_sql" value="true"/&gt;  
              &lt;property name="hibernate.connection.username" value="flussibatch"/&gt;  
              &lt;property name="hibernate.connection.password" value="caposele"/&gt;  
              &lt;property name="hibernate.connection.url" value="jdbc:oracle:thin:@localhost:1521:XE"/&gt; 
          &lt;/properties&gt;
     &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>My applicationContext is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"&gt;
  
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceUnitName" value="fb-persistence" /&gt;
      &lt;/bean&gt;
  
      &lt;bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" /&gt;
      &lt;bean name="pluginDao" class="it.synclab.fb.jpa.dao.impl.PluginDaoImpl" /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>my DAO interface is:</p>
  
  <pre><code>import it.synclab.fb.jpa.entity.Plugin;
  
  public interface PluginDao {
  
      public Plugin load (int id);
  
      public void save(Plugin plg);
  }
  </code></pre>
  
  <p>and my implementation is:</p>
  
  <pre><code>import javax.persistence.EntityManager;
  import javax.persistence.PersistenceContext;
  import org.springframework.transaction.annotation.Transactional;
  import it.synclab.fb.jpa.entity.Plugin;
  
  
  public class PluginDaoImpl implements PluginDao {
  
      private EntityManager entityManager;
  
      @PersistenceContext (unitName="fb-persistence")
      public void setEntityManager(EntityManager entityManager) {
          this.entityManager = entityManager;
      }
  
      @Override
      public Plugin load(int id) {
          return entityManager.find(Plugin.class, id);
      }
  
      @Override
      @Transactional
      public void save(Plugin plg) {
          entityManager.persist(plg);     
      }
  }
  </code></pre>
  
  <p>This is my "horror":</p>
  
  <pre><code>Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: fb-persistence] Unable to configure EntityManagerFactory
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)
      at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)
      at it.synclab.fb.jpa.test.PluginTest.main(PluginTest.java:26)
  Caused by: javax.persistence.PersistenceException: [PersistenceUnit: fb-persistence] Unable to configure EntityManagerFactory
      at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:378)
      at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)
      at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
      at org.springframework.orm.jpa.LocalEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalEntityManagerFactoryBean.java:92)
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
      ... 12 more
  Caused by: org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: it.synclab.fb.jpa.entity.StoreFileGet.idTransaction in it.synclab.fb.jpa.entity.Transaction.listStoreFileGet
      at org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:685)
      at org.hibernate.cfg.annotations.CollectionBinder$1.secondPass(CollectionBinder.java:645)
      at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:65)
      at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1689)
      at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1396)
      at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1348)
      at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1522)
      at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:193)
      at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:1100)
      at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:282)
      at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:366)
      ... 18 more
  </code></pre>