Skip to content

Commit c119de4

Browse files
committed
communicate intent more clearly
1 parent ba677a9 commit c119de4

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

hibernate4/src/main/java/com/fasterxml/jackson/datatype/hibernate4/HibernateProxySerializer.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,21 @@ protected Object findProxied(HibernateProxy proxy)
202202
return init.getImplementation();
203203
}
204204

205-
// Alas, hibernate offers no public api to access this information, so we must resort to ugly hacks ...
205+
/**
206+
* Inspects a Hibernate proxy to try and determine the name of the identifier property
207+
* (Hibernate proxies know the getter of the identifier property because it receives special
208+
* treatment in the invocation handler). Alas, the field storing the method reference is
209+
* private and has no getter, so we must resort to ugly reflection hacks to read its value ...
210+
*/
206211
protected static class ProxyReader {
207212

208213
// static final so the JVM can inline the lookup
209-
private static final Field getIdentifierMethod;
214+
private static final Field getIdentifierMethodField;
210215

211216
static {
212217
try {
213-
getIdentifierMethod = BasicLazyInitializer.class.getDeclaredField("getIdentifierMethod");
214-
getIdentifierMethod.setAccessible(true);
218+
getIdentifierMethodField = BasicLazyInitializer.class.getDeclaredField("getIdentifierMethod");
219+
getIdentifierMethodField.setAccessible(true);
215220
} catch (Exception e) {
216221
// should never happen: the field exists in all versions of hibernate 4 and 5
217222
throw new RuntimeException(e);
@@ -223,7 +228,7 @@ protected static class ProxyReader {
223228
*/
224229
static String getIdentifierPropertyName(LazyInitializer init) {
225230
try {
226-
Method idGetter = (Method) getIdentifierMethod.get(init);
231+
Method idGetter = (Method) getIdentifierMethodField.get(init);
227232
if (idGetter == null) {
228233
return null;
229234
}

0 commit comments

Comments
 (0)