Spring WebSphere加载时编织没有增强jpa实体

Spring WebSphere加载时编织没有增强jpa实体,spring,jpa,websphere,load-time-weaving,Spring,Jpa,Websphere,Load Time Weaving,我已经用我的最新配置重新编写了我的整个问题。我已经改变和测试多次,仍然没有找到适当的解决方案 在我的项目中,我很难为jpa类增强启用加载时编织 我使用的是WebSphere8.5,它反过来又使用OpenJPA2.2.2。我有一个Ear文件和一个War文件,以及许多包含JPA实体和自定义命名的persistence.xml文件的依赖JAR 像这样: MyApp.ear |-- lib ## contains spring files and other shared libraries |-- u

我已经用我的最新配置重新编写了我的整个问题。我已经改变和测试多次,仍然没有找到适当的解决方案

在我的项目中,我很难为jpa类增强启用加载时编织

我使用的是WebSphere8.5,它反过来又使用OpenJPA2.2.2。我有一个
Ear
文件和一个
War
文件,以及许多包含
JPA
实体和自定义命名的
persistence.xml
文件的依赖JAR

像这样:

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
我在control.jar中的主上下文文件control-context.xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="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">

    <!-- The transactions in this app is driven through annotations -->
    <tx:annotation-driven/>
    <context:load-time-weaver />

    <!-- Defining our datasource here enables us to inject a JPA persistence context using spring -->

    <jee:jndi-lookup id="oneDS" jndi-name="jdbc/oneDS" expected-type="javax.sql.DataSource" cache="true"/>
    <jee:jndi-lookup id="twoDS" jndi-name="jdbc/twoDS" expected-type="javax.sql.DataSource" cache="true"/>

    <!-- =================== -->
    <!--      EMF SETUP      -->
    <!-- =================== -->

    <!-- COMMON EMF PROPERTIES -->
    <bean id="baseEMF" abstract="true" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
        <property name="persistenceProvider">
            <bean class="org.apache.openjpa.persistence.PersistenceProviderImpl" />
        </property>
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
        <property name="jpaPropertyMap" ref="jpaPropertiesMap" />
        <property name="jpaDialect">
            <bean class="org.springframework.orm.jpa.vendor.OpenJpaDialect" />
        </property>
    </bean>

    <!-- Merging persistence unit combines all *-persistence.xml files from seperate modules by PU name
         e.g. onePU, twoPU etc.. -->
    <bean id="basePum" class="org.springframework.data.jpa.support.MergingPersistenceUnitManager" abstract="true">
        <!-- store all persistence information in the <module-name>-persistence.xmls located under the custom META-INF
             directory for each module-->
        <property name="persistenceXmlLocation" value="classpath*:META-INF/**/*-persistence.xml" />
        <property name="packagesToScan" value="com.example.myapp.**.model" />
    </bean>

    <!-- COMMON JPA VENDOR ADAPTER PROPERTIES -->
    <bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.OpenJpaVendorAdapter">
        <property name="database" value="DB2"/>
        <property name="generateDdl" value="false"/>
        <!-- I imagine that this would be turned off in production,
             leaving this here for the time being. -->
        <property name="showSql" value="true"/>
    </bean>

    <!-- COMMON JPA PROPERTIES -->
    <util:map id="jpaPropertiesMap">
        <entry key="openjpa.jdbc.DBDictionary" value="db2" />
        <entry key="openjpa.TransactionMode" value="managed" />
        <entry key="openjpa.ConnectionFactoryMode" value="managed" />
        <entry key="openjpa.DynamicEnhancementAgent" value="true"/>
    </util:map>

    <!-- ONE EMF SETUP -->
    <bean id="oneEMF" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" parent="baseEMF">
        <property name="persistenceUnitName" value="onePU" />
        <property name="persistenceUnitManager">
            <bean class="org.springframework.data.jpa.support.MergingPersistenceUnitManager" parent="basePum">
                <property name="defaultJtaDataSource" ref="oneDS" />
                <property name="defaultPersistenceUnitName" value="onePU" />
            </bean>
        </property>
    </bean>

    <!-- TWO EMF SETUP -->
    <bean id="twoEMF" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" parent="baseEMF">
        <property name="persistenceUnitName" value="twoPU" />
        <property name="persistenceUnitManager">
            <bean class="org.springframework.data.jpa.support.MergingPersistenceUnitManager" parent="basePum">
                <property name="defaultJtaDataSource" ref="twoDS" />
                <property name="defaultPersistenceUnitName" value="twoPU" />
            </bean>
        </property>

    </bean>

    <!-- the default unit of work manager is located at 'java:comp/websphere/UOWManager' -->
    <bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>

    <!-- Automatically picked up by the spring entity manager factory -->

</beans>
我的实体都有@Entity和适当的@Id标记,还有什么,它们以前一直作为实体工作,我没有修改它们,所以我确信我的实体是有效的

现在回答问题: 我在我的mod1 jar中设置了一个spring rest jpa资源库,它使用oneEMF:

<jpa:repositories base-package="com.example.myapp.mod1.model.repositories" entity-manager-factory-ref="oneEMF" />

当我在应用程序部署和启动后点击url时,我收到以下消息:

Error 500: org.springframework.web.util.NestedServletException: Request processing failed; 
`-- nested exception is org.springframework.orm.jpa.JpaSystemException: No registered metadata for type "class com.example.myapp.core.model.MyEntity". 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 <openjpa-2.2.2-SNAPSHOT-r422266:1462076 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: No registered metadata for type "class com.example.myapp.core.model.MyEntity". 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).
错误500:org.springframework.web.util.NestedServletException:请求处理失败;
`--嵌套的异常是org.springframework.orm.jpa.JpaSystemException:类型“class com.example.myapp.core.model.MyEntity”没有注册元数据。如果这个类没有被注释为持久性实体或在持久性单元(例如:在orm.xml中)中指定,就会发生这种情况;
`--嵌套的异常是org.apache.openjpa.persistence.PersistenceException:没有注册类型为“class com.example.myapp.core.model.MyEntity”的元数据。如果该类没有被注释为持久性实体或在持久性单元中指定(例如:在orm.xml中),则可能发生这种情况。
为什么我的实体在加载时没有增强?

我已经浪费了很多时间试图配置这个被认为是简单的设置,但是我不知道为什么我没有得到增强。任何帮助或同情都将不胜感激

更新:

在我的war classes文件夹的META-INF目录中放置一个伪persistence.xml已成功触发实体扫描,但从我所读到的内容来看,如果我在spring中使用packagesToScan,则不需要persistence.xml。此包扫描是否涉及将由加载时间编织器增强的实体


谢谢您的时间。

请发布com.example.mymodule.model.SomeEntity类。您是将OpenJPA JAR包含在应用程序中还是使用WebSphere附带的应用程序?请发布您的persistence.xml。如果我需要类路径中的OpenJPA,我可以从哪里获得它?我可以在WebSphere/AppServer/plugins中的plugins文件夹中看到jar。我是否需要手动将其放在我的ear或共享库中,或者是否有某种方式以更为网络化的方式引用它?您不需要openJPA JAR,它们是随WebSphere提供的,但是您需要persistence.xml才能由容器处理注释。Spring建议您可以构造一个没有persistence xml的持久化单元。您是说我还是需要一个持久化xml吗?如果您使用LocalContainerEntityManagerFactoryBean进行基于Spring的扫描,则不需要persistence.xml。您可以在配置中添加标签吗?
Error 500: org.springframework.web.util.NestedServletException: Request processing failed; 
`-- nested exception is org.springframework.orm.jpa.JpaSystemException: No registered metadata for type "class com.example.myapp.core.model.MyEntity". 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 <openjpa-2.2.2-SNAPSHOT-r422266:1462076 nonfatal general error> org.apache.openjpa.persistence.PersistenceException: No registered metadata for type "class com.example.myapp.core.model.MyEntity". 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).