Skip to content

Commit 39b6a87

Browse files
gavinkingmbellade
authored andcommitted
implement equals() / hashCode() for NativeQueryConstructorTransformer
to help the query interpretation cache
1 parent aefc2d1 commit 39b6a87

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

hibernate-core/src/main/java/org/hibernate/jpa/spi/NativeQueryConstructorTransformer.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class NativeQueryConstructorTransformer<T> implements TupleTransformer<T> {
2121

2222
private final Class<T> resultClass;
23-
private Constructor<T> constructor;
23+
private transient Constructor<T> constructor;
2424

2525
private Constructor<T> constructor(Object[] elements) {
2626
if ( constructor == null ) {
@@ -71,4 +71,16 @@ public T transformTuple(Object[] tuple, String[] aliases) {
7171
throw new InstantiationException( "Cannot instantiate query result type", resultClass, e );
7272
}
7373
}
74+
75+
@Override
76+
public boolean equals(Object obj) {
77+
return obj instanceof NativeQueryConstructorTransformer<?> that
78+
&& this.resultClass == that.resultClass;
79+
// should be safe to ignore the cached constructor here
80+
}
81+
82+
@Override
83+
public int hashCode() {
84+
return resultClass.hashCode();
85+
}
7486
}

0 commit comments

Comments
 (0)