0

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.

AlexElin
  • 1,044
  • 14
  • 23
ds2799
  • 59
  • 6

1 Answers1

0

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.

Gavin King
  • 3,182
  • 1
  • 13
  • 11
  • Hi, PersistentSet is returned from the database as there is a lazy association in the fetched object. – ds2799 Aug 02 '20 at 10:48
  • But `PersistentSet` implements `java.util.Set`. – Gavin King Aug 02 '20 at 16:40
  • Hi Gavin, The problem was the framework that does the comparison, it does not work fine when it is supplied with entities containing Persistence Sets.I have written a small code to remove persistent sets, following which code to compare object is working fine. – ds2799 Sep 12 '21 at 13:26