OPENJPA-2197 fix lifecycle method detection

This commit fixes a problem to pick up a JPA lifecycle method
like @PrePersist if there is a method with the same name
(but different parameters) in the class as well.


git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1339509 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Mark Struberg 2012-05-17 07:55:41 +00:00
parent e6a8d377bc
commit 61b023c784
2 changed files with 35 additions and 8 deletions

View File

@ -51,6 +51,14 @@ public class ListenerImpl {
postLoadCount++;
}
// dummy methods for testing OPENJPA-2197
public void postLoad(int someotherValue, String dummyParameter) {
// do nothing. This just breaks the other method ... ;)
}
public void postLoad(int someotherValue) {
// do nothing. This just breaks the other method ... ;)
}
@PreUpdate
public void preUpdate(Object o) {
preUpdateCount++;

View File

@ -2017,14 +2017,33 @@ public class AnnotationPersistenceMetaDataParser
if (c1.isAssignableFrom(c2))
return -1;
else
return 1;
}
int compare = m1.getName ().compareTo (m2.getName ());
if (compare == 0)
return m1.hashCode () - m2.hashCode ();
return compare;
}
}
return 1;
}
int compare = m1.getName().compareTo(m2.getName ());
if (compare != 0) {
return compare;
}
Class<?>[] params1 = m1.getParameterTypes();
Class<?>[] params2 = m2.getParameterTypes();
compare = params1.length - params2.length;
if (compare != 0) {
return compare;
}
// Just using the Method#hashCode() is not enough as it only contains
// the hash of the class + the hash of the NAME of the method...
// Thus if they have the same number of parameters, we need to compare them all
for (int i = 0; i < params1.length; i++) {
compare = params1[i].hashCode() - params2[i].hashCode();
if (compare != 0) {
return compare;
}
}
return 0;
}
}
/**
* An internal class used to mimic the FetchGroup annotation.