diff --git a/common/src/main/java/org/broadleafcommerce/common/extensibility/jpa/MergePersistenceUnitManager.java b/common/src/main/java/org/broadleafcommerce/common/extensibility/jpa/MergePersistenceUnitManager.java index 820f98773a0..943608d0b07 100644 --- a/common/src/main/java/org/broadleafcommerce/common/extensibility/jpa/MergePersistenceUnitManager.java +++ b/common/src/main/java/org/broadleafcommerce/common/extensibility/jpa/MergePersistenceUnitManager.java @@ -243,11 +243,16 @@ public void preparePersistenceUnitInfos() { } // If a class happened to be loaded by the ClassLoader before we had a chance to set up our instrumentation, - // it may not be in a consistent state. We'll detect that here and force the class to be reloaded + // it may not be in a consistent state for (PersistenceUnitInfo pui : mergedPus.values()) { for (String managedClassName : pui.getManagedClassNames()) { if (!entityMarkerClassTransformer.getTransformedClassNames().contains(managedClassName)) { - LOG.error("Should have transformed " + managedClassName + " but didn't"); + LOG.warn("The class " + managedClassName + " is a managed clas within the MergePersistenceUnitManager" + + "but was not detected as being transformed by the EntityMarkerClassTransformer. This " + + "might simply be because " + managedClassName + " is not annotated with @Entity, @MappedSuperclass or @Embeddable" + + ", but is still referenced in a persistence.xml and is being transformed by" + + " PersistenceUnit ClassTransformers. This class should likely be removed from your persistence.xml"); + } } } diff --git a/common/src/main/java/org/broadleafcommerce/common/extensibility/jpa/convert/EntityMarkerClassTransformer.java b/common/src/main/java/org/broadleafcommerce/common/extensibility/jpa/convert/EntityMarkerClassTransformer.java index a5c82d34541..28b6f6b45bf 100644 --- a/common/src/main/java/org/broadleafcommerce/common/extensibility/jpa/convert/EntityMarkerClassTransformer.java +++ b/common/src/main/java/org/broadleafcommerce/common/extensibility/jpa/convert/EntityMarkerClassTransformer.java @@ -21,6 +21,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.broadleafcommerce.common.extensibility.jpa.MergePersistenceUnitManager; import org.broadleafcommerce.common.extensibility.jpa.copy.DirectCopyIgnorePattern; import java.io.ByteArrayInputStream; @@ -37,11 +38,18 @@ import javassist.bytecode.annotation.Annotation; import javax.annotation.Resource; +import javax.persistence.Embeddable; import javax.persistence.Entity; +import javax.persistence.MappedSuperclass; /** - * This class transformer will check to see if there is an @Entity annotation on the given class, and if there is, - * it will add the fully qualified classname of that class to the transformedClassNames list. + *
+ * This class transformer will check to see if there is class that should have been loaded by the {@link MergePersistenceUnitManager} + * (meaning, it has an @Entity, @MappedSuperclass or @Embeddable annotation on it and will be inside of a persistence.xml). + * If it it should have, it will add the fully qualified classname of that class to the transformedClassNames list. + * + *
+ * This is a validation check to ensure that the class transformers are actually working properly
*
* @author Andre Azzolini (apazzolini)
*/
@@ -69,12 +77,11 @@ public byte[] transform(ClassLoader loader, String className, Class> classBein
while(itr.hasNext()) {
Object object = itr.next();
if (AnnotationsAttribute.class.isAssignableFrom(object.getClass())) {
- for (Annotation annotation : ((AnnotationsAttribute) object).getAnnotations()) {
- if (annotation.getTypeName().equals(Entity.class.getName())) {
- LOG.trace("Marking " + convertedClassName + " as transformed");
- transformedClassNames.add(convertedClassName);
- break check;
- }
+ boolean containsTypeLevelAnnotation = containsTypeLevelPersistenceAnnotation(((AnnotationsAttribute) object).getAnnotations());
+ if (containsTypeLevelAnnotation) {
+ LOG.debug("Marking " + convertedClassName + " as transformed");
+ transformedClassNames.add(convertedClassName);
+ break check;
}
}
}
@@ -88,6 +95,17 @@ public byte[] transform(ClassLoader loader, String className, Class> classBein
return null;
}
+ protected boolean containsTypeLevelPersistenceAnnotation(Annotation[] annotations) {
+ for (Annotation annotation : annotations) {
+ if (annotation.getTypeName().equals(Entity.class.getName())
+ || annotation.getTypeName().equals(Embeddable.class.getName())
+ || annotation.getTypeName().equals(MappedSuperclass.class.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
protected boolean isIgnored(String convertedClassName) {
boolean isValidPattern = true;
List