rzo1 commented on code in PR #144:
URL: https://github.com/apache/openjpa/pull/144#discussion_r3689140055


##########
openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java:
##########
@@ -330,4 +332,27 @@ public static Object getManagedInstance(Object o) {
         else
             return o;
     }
+
+    /**
+     * Returns the entity class for the given object, unwrapping any
+     * runtime-generated pcsubclass proxy. For runtime-enhanced entities,
+     * {@code obj.getClass()} returns the generated subclass (e.g.
+     * {@code Order$pcsubclass}), but for {@code equals()}/{@code hashCode()}
+     * comparisons the original entity class should be used.
+     *
+     * @param obj the object whose entity class to determine
+     * @return the original entity class (superclass of pcsubclass), or
+     *         the object's actual class if it is not a pcsubclass
+     * @since 4.2.0
+     */
+    public static Class<?> getEntityClass(Object obj) {
+        if (obj == null) {
+            return null;
+        }
+        Class<?> cls = obj.getClass();
+        if (cls.getName().contains("$pcsubclass")) {

Review Comment:
   Fixed in 2a8d3831c3092ce10811f496fe045ee7d39ba044: getEntityClass now uses 
PCEnhancer.isPCSubclassName() (the counterpart of the name generator) and walks 
superclasses until the name is no longer a generated one, so nested 
pcsubclasses are unwrapped too. Also extracted the "$pcsubclass" literal into 
PCEnhancer.PCSUBCLASS_SUFFIX and added a unit test.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to