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 <j...@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.