title: WebSphere Load-Time weaving not enhancing jpa entities
body: <p>I have re-written my entire question with my latest configuration. I have been changing and testing multiple times and still have not found the proper solution.</p>
  <p>I am having difficulty enabling load-time-weaving for jpa class enhancement in my project.</p>
  <p>I am using <strong>Websphere 8.5</strong> which in turn uses <strong>openjpa 2.2.2</strong>. I have one <strong><code>Ear</code></strong> file with one <strong><code>War</code></strong> and many dependant jars that <strong>contain <code>JPA</code> entities</strong> and <strong>custom named <code>persistence.xml</code></strong> files.</p>
  <p>like so:</p>
  <pre><code>MyApp.ear
  |-- lib ## contains spring files and other shared libraries
  |-- utilJars ## contains my custom made utility jars
  |   |-- core.jar ## core-persistence.xml
  |   |-- core-api.jar ## core entities
  |   |-- mod1.jar ## mod1-persistence.xml
  |   |-- mod1-api.jar ## mod1 entities
  |   `-- control.jar ## depends on all above jars (in **`MANIFEST.MF`**), 
  |                      `contains the main application context (`control-context.xml`) config shown below
  `-- MyWeb.war
  </code></pre>
  <p>My main context file in control.jar called control-context.xml is as follows:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xmlns:jee=&quot;http://www.springframework.org/schema/jee&quot;
         xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;
         xmlns:util=&quot;http://www.springframework.org/schema/util&quot;
         xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
         xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
                             http://www.springframework.org/schema/jee http://schema.spring.io/jee/spring-jee-4.0.xsd
                             http://www.springframework.org/schema/tx http://schema.spring.io/tx/spring-tx-4.0.xsd
                             http://www.springframework.org/schema/util http://schema.spring.io/util/spring-util-4.0.xsd
                             http://www.springframework.org/schema/context http://schema.spring.io/context/spring-context-4.0.xsd&quot;&gt;
  
      &lt;!-- The transactions in this app is driven through annotations --&gt;
      &lt;tx:annotation-driven/&gt;
      &lt;context:load-time-weaver /&gt;
  
      &lt;!-- Defining our datasource here enables us to inject a JPA persistence context using spring --&gt;
  
      &lt;jee:jndi-lookup id=&quot;oneDS&quot; jndi-name=&quot;jdbc/oneDS&quot; expected-type=&quot;javax.sql.DataSource&quot; cache=&quot;true&quot;/&gt;
      &lt;jee:jndi-lookup id=&quot;twoDS&quot; jndi-name=&quot;jdbc/twoDS&quot; expected-type=&quot;javax.sql.DataSource&quot; cache=&quot;true&quot;/&gt;
  
      &lt;!-- =================== --&gt;
      &lt;!--      EMF SETUP      --&gt;
      &lt;!-- =================== --&gt;
  
      &lt;!-- COMMON EMF PROPERTIES --&gt;
      &lt;bean id=&quot;baseEMF&quot; abstract=&quot;true&quot; class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot; &gt;
          &lt;property name=&quot;persistenceProvider&quot;&gt;
              &lt;bean class=&quot;org.apache.openjpa.persistence.PersistenceProviderImpl&quot; /&gt;
          &lt;/property&gt;
          &lt;property name=&quot;jpaVendorAdapter&quot; ref=&quot;jpaVendorAdapter&quot; /&gt;
          &lt;property name=&quot;jpaPropertyMap&quot; ref=&quot;jpaPropertiesMap&quot; /&gt;
          &lt;property name=&quot;jpaDialect&quot;&gt;
              &lt;bean class=&quot;org.springframework.orm.jpa.vendor.OpenJpaDialect&quot; /&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- Merging persistence unit combines all *-persistence.xml files from seperate modules by PU name
           e.g. onePU, twoPU etc.. --&gt;
      &lt;bean id=&quot;basePum&quot; class=&quot;org.springframework.data.jpa.support.MergingPersistenceUnitManager&quot; abstract=&quot;true&quot;&gt;
          &lt;!-- store all persistence information in the &lt;module-name&gt;-persistence.xmls located under the custom META-INF
               directory for each module--&gt;
          &lt;property name=&quot;persistenceXmlLocation&quot; value=&quot;classpath*:META-INF/**/*-persistence.xml&quot; /&gt;
          &lt;property name=&quot;packagesToScan&quot; value=&quot;com.example.myapp.**.model&quot; /&gt;
      &lt;/bean&gt;
  
      &lt;!-- COMMON JPA VENDOR ADAPTER PROPERTIES --&gt;
      &lt;bean id=&quot;jpaVendorAdapter&quot; class=&quot;org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter&quot;&gt;
          &lt;property name=&quot;database&quot; value=&quot;DB2&quot;/&gt;
          &lt;property name=&quot;generateDdl&quot; value=&quot;false&quot;/&gt;
          &lt;!-- I imagine that this would be turned off in production,
               leaving this here for the time being. --&gt;
          &lt;property name=&quot;showSql&quot; value=&quot;true&quot;/&gt;
      &lt;/bean&gt;
  
      &lt;!-- COMMON JPA PROPERTIES --&gt;
      &lt;util:map id=&quot;jpaPropertiesMap&quot;&gt;
          &lt;entry key=&quot;openjpa.jdbc.DBDictionary&quot; value=&quot;db2&quot; /&gt;
          &lt;entry key=&quot;openjpa.TransactionMode&quot; value=&quot;managed&quot; /&gt;
          &lt;entry key=&quot;openjpa.ConnectionFactoryMode&quot; value=&quot;managed&quot; /&gt;
          &lt;entry key=&quot;openjpa.DynamicEnhancementAgent&quot; value=&quot;true&quot;/&gt;
      &lt;/util:map&gt;
  
      &lt;!-- ONE EMF SETUP --&gt;
      &lt;bean id=&quot;oneEMF&quot; class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot; parent=&quot;baseEMF&quot;&gt;
          &lt;property name=&quot;persistenceUnitName&quot; value=&quot;onePU&quot; /&gt;
          &lt;property name=&quot;persistenceUnitManager&quot;&gt;
              &lt;bean class=&quot;org.springframework.data.jpa.support.MergingPersistenceUnitManager&quot; parent=&quot;basePum&quot;&gt;
                  &lt;property name=&quot;defaultJtaDataSource&quot; ref=&quot;oneDS&quot; /&gt;
                  &lt;property name=&quot;defaultPersistenceUnitName&quot; value=&quot;onePU&quot; /&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- TWO EMF SETUP --&gt;
      &lt;bean id=&quot;twoEMF&quot; class=&quot;org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean&quot; parent=&quot;baseEMF&quot;&gt;
          &lt;property name=&quot;persistenceUnitName&quot; value=&quot;twoPU&quot; /&gt;
          &lt;property name=&quot;persistenceUnitManager&quot;&gt;
              &lt;bean class=&quot;org.springframework.data.jpa.support.MergingPersistenceUnitManager&quot; parent=&quot;basePum&quot;&gt;
                  &lt;property name=&quot;defaultJtaDataSource&quot; ref=&quot;twoDS&quot; /&gt;
                  &lt;property name=&quot;defaultPersistenceUnitName&quot; value=&quot;twoPU&quot; /&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
  
      &lt;/bean&gt;
  
      &lt;!-- the default unit of work manager is located at 'java:comp/websphere/UOWManager' --&gt;
      &lt;bean id=&quot;transactionManager&quot; class=&quot;org.springframework.transaction.jta.WebSphereUowTransactionManager&quot;/&gt;
  
      &lt;!-- Automatically picked up by the spring entity manager factory --&gt;
  
  &lt;/beans&gt;
  </code></pre>
  <p>I am using a merging persistence unit manager provided by spring to combine the persistence unit declarations in the custom persistence unit xml's located under <code>META-INF/&lt;module-name&gt;/&lt;module-name&gt;-persistence.xml</code> folder of each jar. e.g. <code>META-INF/core/core-persistence.xml</code>.</p>
  <p>here is one such file:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;persistence xmlns=&quot;http://java.sun.com/xml/ns/persistence&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
               xsi:schemaLocation=&quot;http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance
               http://java.sun.com/xml/ns/persistence http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/persistence/persistence_2_0.xsd&quot; version=&quot;2.0&quot;&gt;
      &lt;persistence-unit name=&quot;onePU&quot;&gt;
          &lt;class&gt;com.example.myapp.core.model.MyEntity&lt;/class&gt;
          &lt;class&gt;com.example.myapp.core.model.MyEntityId&lt;/class&gt;
          &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  <p>My entities all have @Entity and proper @Id tags and what not, They have been working as entities before and I haven't modified them, so I'm sure that my entities are valid.</p>
  <h2>And now for the QUESTION:</h2>
  <p>I have a spring rest jpa resource repository set up in my mod1 jar that uses the oneEMF:</p>
  <pre><code>&lt;jpa:repositories base-package=&quot;com.example.myapp.mod1.model.repositories&quot; entity-manager-factory-ref=&quot;oneEMF&quot; /&gt;
  </code></pre>
  <p>when i hit the url after the application is deployed and started, I get this message:</p>
  <pre><code>Error 500: org.springframework.web.util.NestedServletException: Request processing failed; 
  `-- nested exception is org.springframework.orm.jpa.JpaSystemException: No registered metadata for type &quot;class com.example.myapp.core.model.MyEntity&quot;. This can happen if this class has not been annotated as a persistent entity or specified in the persistence unit (ex: in the orm.xml). ; 
  `-- nested exception is &lt;openjpa-2.2.2-SNAPSHOT-r422266:1462076 nonfatal general error&gt; org.apache.openjpa.persistence.PersistenceException: No registered metadata for type &quot;class com.example.myapp.core.model.MyEntity&quot;. This can happen if this class has not been annotated as a persistent entity or specified in the persistence unit (ex: in the orm.xml).
  </code></pre>
  <blockquote>
  <p><em><strong>Why are my entities not enhancing at load time?</strong></em></p>
  </blockquote>
  <p>I have lost many hours attempting to configure this supposedly simple setup, however I am at a loss as to why the enhancement is not occuring for me. any help or even sympathy would be much appreciated.</p>
  <p><strong>UPDATE:</strong></p>
  <p>placing a dummy persistence.xml in the META-INF directory of my war classes folder has managed to trigger the entity scanning, but from what I've read, I don't need the persistence.xml if I am using packagesToScan with spring. Does this package scanning refer to entities that will be enhanced by the load-time-weaver?</p>
  <p>Thank you for your time.</p>