Change Hibernate's PersistentSet to HashSet

1.2k Views Asked by At

I have a program that compares objects from 2 databases.

I have objects from 2 different databases and I have to compare them. The problem is that hibernate returns a PersistentSet and this causes the program to fail as it only supports Java Collections.

Is there an elegant way to change this PersistentSet to HashSet. I have already tried Introspector approach but it still seems not to work with this comparator.

1

There are 1 best solutions below

3
Gavin King On

Your program is not supposed to depend directly on the PersistentSet class, that is considered an internal implementation detail of Hibernate.

Instead, you should use the type java.util.Set in your Java code (which PersistentSet implements).

Just don't try to cast the PersistentSet to HashSet. Instead assign it to java.util.Set, as in all Hibernate code examples.