0

最新の構成で質問全体を書き直しました。私は何度も変更とテストを行ってきましたが、まだ適切な解決策が見つかりません。

プロジェクトで jpa クラス拡張のロード時ウィービングを有効にするのが困難です。

私はopenjpa 2.2.2を使用するWebsphere 8.5を使用しています。エンティティカスタムの名前付きファイルを含む1 つ以上の依存 jar を持つ 1 つのファイルがあります。EarWarJPApersistence.xml

そのようです:

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-context.xml と呼ばれる control.jar 内のメイン コンテキスト ファイルは次のとおりです。

<?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>

META-INF/<module-name>/<module-name>-persistence.xmlSpring が提供するマージ永続ユニット マネージャーを使用して、各 jar のフォルダーの下にあるカスタム永続ユニット xml の永続ユニット宣言を結合しています。例えばMETA-INF/core/core-persistence.xml

そのようなファイルの 1 つを次に示します。

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="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" version="2.0">
    <persistence-unit name="onePU">
        <class>com.example.myapp.core.model.MyEntity</class>
        <class>com.example.myapp.core.model.MyEntityId</class>
        <exclude-unlisted-classes>true</exclude-unlisted-classes>
    </persistence-unit>
</persistence>

私のエンティティにはすべて @Entity と適切な @Id タグがあり、そうでないものはありません。以前はエンティティとして機能しており、変更していないため、エンティティが有効であると確信しています。

そして今、質問のために:

oneEMF を使用する mod1 jar に、Spring Rest jpa リソース リポジトリをセットアップしました。

<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).

読み込み時にエンティティが強化されないのはなぜですか?

このおそらく単純なセットアップを構成しようとして何時間も無駄にしましたが、なぜ機能強化が行われないのか途方に暮れています. 助けや同情さえあれば大歓迎です。

アップデート:

war classes フォルダーの META-INF ディレクトリにダミーの persistence.xml を配置すると、エンティティ スキャンがトリガーされましたが、読んだ内容から、spring で packagesToScan を使用している場合、persistence.xml は必要ありません。このパッケージ スキャンは、load-time-weaver によって強化されるエンティティを参照していますか?

お時間をいただきありがとうございます。

4

0 に答える 0