You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2019/06/27 10:47:39 UTC

[tomee] branch master updated (3be5d3a -> 8f40dad)

This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git.


    from 3be5d3a  Merge pull request #494 from cesarhernandezgt/TOMEE-2549
     new ac7ad0c  TOMEE-2547 do not add openejb-cmp-generated.xml if it is already included in the <mapping-file> elements of the persistence unit.
     new a68f21d  TOMEE-2548 Adding (currently failing) test for Hibernate
     new 70da116  Explicitly check where a openejb-cmp-generated-orm.xml descriptor may have been included incorrectly.
     new 7a04d4e  Merge branch 'master' of https://github.com/jgallimore/tomee
     new 8f40dad  Merge remote-tracking branch 'upstream/master'

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../tests/cmp/sample/CustomOrmXmlEarTest.java      |  2 +-
 ...Test.java => CustomOrmXmlHibernateEarTest.java} | 22 ++++++--
 .../src/test/resources/arquillian.xml              | 22 ++++++++
 .../arquillian/tests/cmp/sample/custom-orm.xml     |  6 +--
 .../{persistence.xml => persistence-hibernate.xml} | 10 ++--
 .../arquillian/tests/cmp/sample/persistence.xml    |  4 +-
 arquillian/arquillian-tomee-tests/pom.xml          | 58 ++++++++++++++++++++++
 .../apache/openejb/config/CmpJpaConversion.java    | 28 ++++++++---
 .../openejb/core/cmp/cmp2/Cmp2Generator.java       |  2 +-
 9 files changed, 133 insertions(+), 21 deletions(-)
 copy arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/{CustomOrmXmlEarTest.java => CustomOrmXmlHibernateEarTest.java} (82%)
 copy arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/{persistence.xml => persistence-hibernate.xml} (79%)


[tomee] 02/05: TOMEE-2548 Adding (currently failing) test for Hibernate

Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit a68f21d1aafeab53ebe3c55415e4739476045409
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Tue Jun 25 17:23:55 2019 +0100

    TOMEE-2548 Adding (currently failing) test for Hibernate
---
 .../cmp/sample/CustomOrmXmlHibernateEarTest.java   | 106 +++++++++++++++++++++
 .../src/test/resources/arquillian.xml              |  22 +++++
 .../arquillian/tests/cmp/sample/custom-orm.xml     |   4 +-
 .../{persistence.xml => persistence-hibernate.xml} |   8 +-
 .../arquillian/tests/cmp/sample/persistence.xml    |   2 +-
 arquillian/arquillian-tomee-tests/pom.xml          |  58 +++++++++++
 6 files changed, 193 insertions(+), 7 deletions(-)

diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlHibernateEarTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlHibernateEarTest.java
new file mode 100644
index 0000000..2eb9302
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlHibernateEarTest.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.openejb.arquillian.tests.cmp.sample;
+
+import org.apache.ziplock.IO;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.ClassLoaderAsset;
+import org.jboss.shrinkwrap.api.spec.EnterpriseArchive;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.resolver.api.maven.Maven;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * @version $Rev$ $Date$
+ */
+@RunWith(Arquillian.class)
+public class CustomOrmXmlHibernateEarTest {
+
+    @ArquillianResource
+    private URL url;
+
+    @Deployment(testable = false)
+    public static EnterpriseArchive createDeployment() {
+
+        final JavaArchive clientJar = ShrinkWrap.create(JavaArchive.class, "client.jar")
+                .addClasses(ActorDetails.class, LocalActor.class, LocalActorHome.class,
+                        LocalMovie.class, LocalMovieHome.class, MovieDetails.class,
+                        MoviesBusiness.class, MoviesBusinessHome.class);
+
+        final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb-jar.jar")
+                .addClasses(ActorBean.class, MovieBean.class, MovieDetails.class, MoviesBusinessBean.class)
+                .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml"), "META-INF/openejb-cmp-generated-orm.xml")
+                .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/persistence-hibernate.xml"), "META-INF/persistence.xml")
+                .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/openejb-jar.xml"), "META-INF/openejb-jar.xml")
+                .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/ejb-jar.xml"), "META-INF/ejb-jar.xml");
+
+        final WebArchive testWar = ShrinkWrap.create(WebArchive.class, "test.war")
+                .addClass(MoviesServlet.class)
+                .addAsWebInfResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/web.xml"), "web.xml");
+
+        final File[] hibernateDependencies = Maven.resolver().resolve(
+    "org.hibernate:hibernate-entitymanager:4.3.9.Final",
+            "org.hibernate:hibernate-core:4.3.9.Final",
+            "org.hibernate.common:hibernate-commons-annotations:4.0.5.Final",
+            "antlr:antlr:2.7.7",
+            "org.jboss:jandex:1.1.0.Final",
+            "org.jboss.logging:jboss-logging:3.1.3.GA",
+            "org.jboss.logging:jboss-logging-annotations:1.2.0.Beta1",
+            "dom4j:dom4j:1.6.1",
+            "org.javassist:javassist:3.18.1-GA",
+            "mysql:mysql-connector-java:5.1.13"
+        ).withoutTransitivity().asFile();
+        
+        final EnterpriseArchive archive = ShrinkWrap.create(EnterpriseArchive.class, "test.ear")
+                .addAsLibrary(clientJar)
+                .addAsLibraries(hibernateDependencies)
+                .addAsModule(ejbJar)
+                .addAsModule(testWar);
+
+        System.out.println(archive.toString(true));
+        return archive;
+    }
+
+
+    @Test
+    @RunAsClient
+    public void checkCmpJpaEntityORMMappings() throws Exception {
+        final String output = IO.slurp(new URL(url.toExternalForm() + "/test/test/"));
+        System.out.println(output);
+
+        Assert.assertTrue(output.contains("TABLE_NAME: ACTOR, COLUMN_NAME: ACTORID, DATA_TYPE: INTEGER, CHARACTER_MAXIMUM_LENGTH: null"));
+        Assert.assertTrue(output.contains("TABLE_NAME: ACTOR, COLUMN_NAME: ACTOR_NAME, DATA_TYPE: CHARACTER VARYING, CHARACTER_MAXIMUM_LENGTH: 250"));
+        Assert.assertTrue(output.contains("TABLE_NAME: ACTOR_MOVIE, COLUMN_NAME: ACTORS_ACTORID, DATA_TYPE: INTEGER, CHARACTER_MAXIMUM_LENGTH: null"));
+        Assert.assertTrue(output.contains("TABLE_NAME: ACTOR_MOVIE, COLUMN_NAME: MOVIES_MOVIEID, DATA_TYPE: INTEGER, CHARACTER_MAXIMUM_LENGTH: null"));
+        Assert.assertTrue(output.contains("TABLE_NAME: MOVIE, COLUMN_NAME: MOVIEID, DATA_TYPE: INTEGER, CHARACTER_MAXIMUM_LENGTH: null"));
+        Assert.assertTrue(output.contains("TABLE_NAME: MOVIE, COLUMN_NAME: GENRE, DATA_TYPE: CHARACTER VARYING, CHARACTER_MAXIMUM_LENGTH: 255"));
+        Assert.assertTrue(output.contains("TABLE_NAME: MOVIE, COLUMN_NAME: MOVIE_NAME, DATA_TYPE: CHARACTER VARYING, CHARACTER_MAXIMUM_LENGTH: 250"));
+
+        final String[] split = output.split("\r?\n");
+        Assert.assertEquals(7, split.length);
+    }
+}
\ No newline at end of file
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
index 8640e8e..eb1807a 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
@@ -113,6 +113,28 @@
       </property>
     </configuration>
   </container>
+  <container qualifier="tomee-remote-hibernate">
+    <configuration>
+      <property name="httpPort">-1</property>
+      <property name="ajpPort">-1</property>
+      <property name="stopPort">-1</property>
+      <property name="dir">target/tomee-remote</property>
+      <property name="appWorkingDir">target/arquillian-remote-working-dir</property>
+      <property name="portRange">33001-36000</property>
+      <property name="cleanOnStartUp">true</property>
+      <property name="properties">
+        My\ DataSource.JdbcUrl = jdbc:hsqldb:mem:hsqldb
+        My\ Unmanaged\ DataSource.JdbcUrl = jdbc:hsqldb:mem:hsqldb
+        openejb.classloader.forced-load=org.apache.openejb.arquillian.tests
+        openejb.ear.use-as-webcontext-base=true
+        embedded = false
+
+        # try to save some permgen mem
+        openejb.cdi.activated-on-ejb = false
+        openejb.descriptors.output = true
+      </property>
+    </configuration>
+  </container>
   <container qualifier="tomee-remote-secpol">
     <configuration>
       <property name="httpPort">-1</property>
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml
index 22dbae5..b6414e4 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml
@@ -16,7 +16,7 @@
     See the License for the specific language governing permissions and
     limitations under the License.
 -->
-<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="1.0">
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm" version="2.0">
     <entity class="openejb.org.apache.openejb.arquillian.tests.cmp.sample.Movie" name="Movie">
         <description>CustomOrmXmlTest#MovieBean</description>
         <table/>
@@ -31,7 +31,7 @@
                 <column name="movie_name" length="250"/>
             </basic>
             <basic name="genre"/>
-            <many-to-many mapped-by="movies" name="actors"/>
+            <many-to-many mapped-by="movies" name="actors" />
         </attributes>
     </entity>
     <entity class="openejb.org.apache.openejb.arquillian.tests.cmp.sample.Actor" name="Actor">
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence-hibernate.xml
similarity index 82%
copy from arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml
copy to arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence-hibernate.xml
index 05667e4..e7a437a 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence-hibernate.xml
@@ -18,15 +18,15 @@
 -->
 <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
     <persistence-unit name="cmp" transaction-type="JTA">
+        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
         <jta-data-source>My DataSource</jta-data-source>
         <non-jta-data-source>My Unmanaged DataSource</non-jta-data-source>
         <mapping-file>META-INF/openejb-cmp-generated-orm.xml</mapping-file>
         <class>openejb.org.apache.openejb.arquillian.tests.cmp.sample.Movie</class>
         <class>openejb.org.apache.openejb.arquillian.tests.cmp.sample.Actor</class>
         <properties>
-            <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true, Indexes=false, IgnoreErrors=true)"/>
-            <property name="openjpa.Log" value="DefaultLevel=INFO"/>
-            <property name="eclipselink.ddl-generation" value="create-tables"/>
+            <property name="hibernate.hbm2ddl.auto" value="update"/>
+            <property name="hibernate.show_sql" value="true" />
         </properties>
     </persistence-unit>
-</persistence>
+</persistence>
\ No newline at end of file
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml
index 05667e4..ce03420 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml
@@ -29,4 +29,4 @@
             <property name="eclipselink.ddl-generation" value="create-tables"/>
         </properties>
     </persistence-unit>
-</persistence>
+</persistence>
\ No newline at end of file
diff --git a/arquillian/arquillian-tomee-tests/pom.xml b/arquillian/arquillian-tomee-tests/pom.xml
index c665903..bab84f3 100644
--- a/arquillian/arquillian-tomee-tests/pom.xml
+++ b/arquillian/arquillian-tomee-tests/pom.xml
@@ -121,6 +121,64 @@
       <version>${project.version}</version>
     </dependency>
 
+
+    <!-- for tests with Hibernate -->
+
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-entitymanager</artifactId>
+      <version>4.3.9.Final</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-core</artifactId>
+      <version>4.3.9.Final</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.hibernate.common</groupId>
+      <artifactId>hibernate-commons-annotations</artifactId>
+      <version>4.0.5.Final</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>antlr</groupId>
+      <artifactId>antlr</artifactId>
+      <version>2.7.7</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jandex</artifactId>
+      <version>1.1.0.Final</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging</artifactId>
+      <version>3.1.3.GA</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-annotations</artifactId>
+      <version>1.2.0.Beta1</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>dom4j</groupId>
+      <artifactId>dom4j</artifactId>
+      <version>1.6.1</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.javassist</groupId>
+      <artifactId>javassist</artifactId>
+      <version>3.18.1-GA</version>
+      <scope>provided</scope>
+    </dependency>
+
     <!-- just to get it in the correct order -->
     <dependency>
       <groupId>${project.groupId}</groupId>


[tomee] 05/05: Merge remote-tracking branch 'upstream/master'

Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 8f40dad1e7abc73282af050f7fb23e8f44152352
Merge: 7a04d4e 3be5d3a
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Thu Jun 27 11:47:15 2019 +0100

    Merge remote-tracking branch 'upstream/master'

 examples/access-timeout/README_es.adoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[tomee] 04/05: Merge branch 'master' of https://github.com/jgallimore/tomee

Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 7a04d4e3197f0d61d7309f7ae15deded8671f513
Merge: 70da116 3c0e995
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Thu Jun 27 11:46:55 2019 +0100

    Merge branch 'master' of https://github.com/jgallimore/tomee

 pom.xml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[tomee] 03/05: Explicitly check where a openejb-cmp-generated-orm.xml descriptor may have been included incorrectly.

Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit 70da11645afc940ddaea4fd60bd388ae525a1808
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Thu Jun 27 11:45:10 2019 +0100

    Explicitly check where a openejb-cmp-generated-orm.xml descriptor may have been included
    incorrectly.
---
 .../arquillian/tests/cmp/sample/custom-orm.xml     |  4 ++--
 .../apache/openejb/config/CmpJpaConversion.java    | 22 +++++++++++++++++-----
 .../openejb/core/cmp/cmp2/Cmp2Generator.java       |  2 +-
 3 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml
index b6414e4..2605550 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml
@@ -31,7 +31,7 @@
                 <column name="movie_name" length="250"/>
             </basic>
             <basic name="genre"/>
-            <many-to-many mapped-by="movies" name="actors" />
+            <many-to-many mapped-by="movies" name="actors" target-entity="openejb.org.apache.openejb.arquillian.tests.cmp.sample.Actor" access="FIELD"/>
         </attributes>
     </entity>
     <entity class="openejb.org.apache.openejb.arquillian.tests.cmp.sample.Actor" name="Actor">
@@ -47,7 +47,7 @@
             <basic name="name">
                 <column name="actor_name" length="250"/>
             </basic>
-            <many-to-many name="movies"/>
+            <many-to-many name="movies" target-entity="openejb.org.apache.openejb.arquillian.tests.cmp.sample.Movie" access="FIELD"/>
         </attributes>
     </entity>
 </entity-mappings>
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java b/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
index be9dbbd..1acac8a 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
@@ -134,7 +134,6 @@ class CmpJpaConversion implements DynamicDeployer {
             appModule.setCmpMappings(cmpMappings);
         }
 
-        // todo scan existing persistence module for all entity mappings and don't generate mappings for them
 
         final Set<String> definedMappedClasses = new HashSet<>();
 
@@ -151,12 +150,12 @@ class CmpJpaConversion implements DynamicDeployer {
             }
         }
 
-        // we process this one jar-file at a time...each contributing to the 
-        // app mapping data 
+        // we process this one jar-file at a time...each contributing to the
+        // app mapping data
         for (final EjbModule ejbModule : appModule.getEjbModules()) {
             final EjbJar ejbJar = ejbModule.getEjbJar();
 
-            // scan for CMP entity beans and merge the data into the collective set 
+            // scan for CMP entity beans and merge the data into the collective set
             for (final EnterpriseBean enterpriseBean : ejbJar.getEnterpriseBeans()) {
                 if (isCmpEntity(enterpriseBean)) {
                     processEntityBean(ejbModule, definedMappedClasses, cmpMappings, (EntityBean) enterpriseBean);
@@ -164,7 +163,7 @@ class CmpJpaConversion implements DynamicDeployer {
             }
 
             // if there are relationships defined in this jar, get a list of the defined
-            // entities and process the relationship maps. 
+            // entities and process the relationship maps.
             final Relationships relationships = ejbJar.getRelationships();
             if (relationships != null) {
 
@@ -193,8 +192,21 @@ class CmpJpaConversion implements DynamicDeployer {
         if (!cmpMappings.getEntity().isEmpty()) {
             final PersistenceUnit persistenceUnit = getCmpPersistenceUnit(appModule);
 
+            final boolean generatedOrmXmlProvided = appModule.getClassLoader().getResource(GENERATED_ORM_XML) != null;
             if (! persistenceUnit.getMappingFile().contains(GENERATED_ORM_XML)) {
+                // explicit check for openejb-cmp-generated-orm, as this is generated and added to <mapping-file>
+                if (generatedOrmXmlProvided) {
+                    LOGGER.warning("App module " + appModule.getModuleId() + " provides " + GENERATED_ORM_XML + ", but does not " +
+                            "specify it using <mapping-file> in persistence.xml for the CMP persistence unit, and it may conflict " +
+                            "with the generated mapping file. Consider renaming the file and explicitly referencing it in persistence.xml");
+                }
                 persistenceUnit.getMappingFile().add(GENERATED_ORM_XML);
+            } else {
+                if (generatedOrmXmlProvided) {
+                    LOGGER.warning("App module " + appModule.getModuleId() + " provides " + GENERATED_ORM_XML + " and additionally "
+                            + cmpMappings.getEntity().size() + "mappings have been generated. Consider renaming the " + GENERATED_ORM_XML + " in " +
+                            "your deployment archive to avoid any conflicts.");
+                }
             }
 
             for (final Entity entity : cmpMappings.getEntity()) {
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/cmp2/Cmp2Generator.java b/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/cmp2/Cmp2Generator.java
index e04e549..de64f4a 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/cmp2/Cmp2Generator.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/cmp2/Cmp2Generator.java
@@ -751,7 +751,7 @@ public class Cmp2Generator implements Opcodes {
 
         // return this.${cmrField.name}Cmr.get(this.${cmdField.name});  
         // this takes the value stored in the CMR field (which might be a single value or 
-        // a Set or Collection), and hands it to the appropriate accessor. 
+        // a Set or Collection), and hands it to the appropriate accessor.
         mv.visitMethodInsn(INVOKEVIRTUAL, cmrField.getAccessorInternalName(), "get", cmrField.getCmrStyle().getGetterDescriptor(), false);
         // if the style is a single value, then we're going to need to cast this 
         // to the target class before returning.  


[tomee] 01/05: TOMEE-2547 do not add openejb-cmp-generated.xml if it is already included in the elements of the persistence unit.

Posted by jg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jgallimore pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee.git

commit ac7ad0c4dc024a66f99d46d77f1907993c5abe95
Author: Jonathan Gallimore <jo...@jrg.me.uk>
AuthorDate: Tue Jun 25 15:36:14 2019 +0100

    TOMEE-2547 do not add openejb-cmp-generated.xml if it is already
    included in the <mapping-file> elements of the persistence unit.
---
 .../openejb/arquillian/tests/cmp/sample/CustomOrmXmlEarTest.java    | 2 +-
 .../org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml  | 2 +-
 .../src/main/java/org/apache/openejb/config/CmpJpaConversion.java   | 6 +++++-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlEarTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlEarTest.java
index da042bc..550f9ad 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlEarTest.java
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/cmp/sample/CustomOrmXmlEarTest.java
@@ -51,7 +51,7 @@ public class CustomOrmXmlEarTest {
 
         final JavaArchive ejbJar = ShrinkWrap.create(JavaArchive.class, "ejb-jar.jar")
                 .addClasses(ActorBean.class, MovieBean.class, MovieDetails.class, MoviesBusinessBean.class)
-                .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml"), "META-INF/custom-orm.xml")
+                .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/custom-orm.xml"), "META-INF/openejb-cmp-generated-orm.xml")
                 .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml"), "META-INF/persistence.xml")
                 .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/openejb-jar.xml"), "META-INF/openejb-jar.xml")
                 .addAsResource(new ClassLoaderAsset("org/apache/openejb/arquillian/tests/cmp/sample/ejb-jar.xml"), "META-INF/ejb-jar.xml");
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml
index 69b8971..05667e4 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/org/apache/openejb/arquillian/tests/cmp/sample/persistence.xml
@@ -20,7 +20,7 @@
     <persistence-unit name="cmp" transaction-type="JTA">
         <jta-data-source>My DataSource</jta-data-source>
         <non-jta-data-source>My Unmanaged DataSource</non-jta-data-source>
-        <mapping-file>META-INF/custom-orm.xml</mapping-file>
+        <mapping-file>META-INF/openejb-cmp-generated-orm.xml</mapping-file>
         <class>openejb.org.apache.openejb.arquillian.tests.cmp.sample.Movie</class>
         <class>openejb.org.apache.openejb.arquillian.tests.cmp.sample.Actor</class>
         <properties>
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java b/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
index 0c3bf21..be9dbbd 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
@@ -103,6 +103,7 @@ class CmpJpaConversion implements DynamicDeployer {
             "pcDetachedState",
             "serialVersionUID"
     )));
+    public static final String GENERATED_ORM_XML = "META-INF/openejb-cmp-generated-orm.xml";
 
     private static EntityMappings readEntityMappings(final String location, final AppModule appModule) {
 
@@ -192,7 +193,10 @@ class CmpJpaConversion implements DynamicDeployer {
         if (!cmpMappings.getEntity().isEmpty()) {
             final PersistenceUnit persistenceUnit = getCmpPersistenceUnit(appModule);
 
-            persistenceUnit.getMappingFile().add("META-INF/openejb-cmp-generated-orm.xml");
+            if (! persistenceUnit.getMappingFile().contains(GENERATED_ORM_XML)) {
+                persistenceUnit.getMappingFile().add(GENERATED_ORM_XML);
+            }
+
             for (final Entity entity : cmpMappings.getEntity()) {
                 if (!persistenceUnit.getClazz().contains(entity.getClazz())) {
                     persistenceUnit.getClazz().add(entity.getClazz());