Getting Invalid reference- com.thoughtworks.xstream.converters.ConversionException: Invalid reference during Hibernate migration from 5.4.32 to 6.5.2

Issue I am encountering the following error during data processing or object deserialization using XStream:

com.thoughtworks.xstream.converters.ConversionException: Invalid reference : Invalid reference ---- Debugging information ---- message : Invalid reference reference : …/…/storedSnapshot/[EntityName] referenced-type : [EntityName] referenceable : true class : java.util.HashSet required-type : java.util.HashSet converter-type : com.thoughtworks.xstream.converters.collections.CollectionConverter path : /[EntityPath]/[EntityName] line number : 1 class[1] : org.hibernate.collection.spi.PersistentSet required-type[1] : org.hibernate.collection.spi.PersistentSet converter-type[1] : com.thoughtworks.xstream.converters.reflection.ReflectionConverter class[2] : [EntityClass] required-type[2] : [EntityClass] version : not available

The error occurs when I try to load a Hibernate session or when attempting to deserialize an object using XStream.

Steps Taken:

  • I have reviewed the code, particularly the mappings and data relations, but the error persists.
  • The issue seems related to references in the XStream conversion process and all Set are loading form parent Entity and Lazy loading is not working.
  • I attempted to update the XStream configuration to handle collections and references properly, but no resolution so far.

Environment:

  • Hibernate: [6.5.2]
  • XStream: [1.4.20]
  • Java: [17]

What I Tried:

  • XStream(); xstream.setMode(XStream.NO_REFERENCES); String xml1= xstream.toXML(policy);
  • Adjusted the XStream security permissions to allow references.
  • Hibernate.enable_lazy_load_no_trans true in in hibernate.cfg file. We are not using Annotation in our projects, only hbm file mappings

Question: What could be causing the ConversionException during the deserialization process, and how can I resolve this issue? Are there specific configuration changes required in XStream or Hibernate for managing collections and references?

Additional Information: If there are any known bugs or incompatibilities between Hibernate and XStream that could trigger this error, any insight would be appreciated.

You should better ask the maintainers of XStream about this since you’re experiencing an exception thrown by that library. Hibernate ORM doesn’t “support” integration with that library, so this community most likely won’t be able to help you.

I am encountering an issue with ORM while loading a subset in Hibernate 6.5.2 migration. Lazy loading is not functioning as expected, despite configuring everything properly. The problem arises after the DAO object loads with values for the set and subset, where XStream comes into play after loading objects from DAO select query.

We would like assistance with the necessary configuration to resolve this issue.

<?xml version='1.0' encoding='UTF-8'?>
 	 <property name="connection.datasource">java://comp/env/jdbc/***</property>

    <
	<!--For MSSQL-->
    <property name="dialect">com.csc.pt.hiber.MSSQLDialect2012CSC</property>
    <!-- Session/Transaction -->
	<property name="hibernate.current_session_context_class">thread</property>
	
	

	<!-- Use Scrollable Result Set -->
	<property name="hibernate.jdbc.use_scrollable_resultset">true</property>
	<!--  more verbose logs -->
	<property name="hibernate.show_sql">true</property>
	<property name="hibernate.format_sql">true</property>
	<property name="hibernate.use_sql_comments">false</property>
	<property name="hibernate.generate_statistics">false</property>
	<property name="hibernate.query.startup_check">false</property>
	
	<!-- <property name="hibernate.connection.autocommit">true</property>  -->
	<property name="connection.isolation">1</property>

	<!-- performance factors -->
	<property name="hibernate.jdbc.batch_size">50</property>
	<property name="hibernate.default_batch_fetch_size">8</property>
	<property name="hibernate.default_lazy">true</property>
	<!-- FSIT#179159 Resolution#65256 - Start -->
	<property name="hibernate.order_inserts">true</property>
	<!-- FSIT#179159 Resolution#65256 - End -->

 	<!--  second level cache -->
	<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.EhCacheProvider</property>
	<property name="hibernate.cache.use_minimal_puts">true</property>
	<property name="hibernate.cache.use_query_cache">false</property>
	<property name="hibernate.cache.use_second_level_cache">false</property>
	<property name="hibernate.enable_lazy_load_no_trans">true</property>
	<property name="hibernate.cache.region.factory_class">jcache</property>
	<property name="hibernate.javax.cache.provider">org.ehcache.jsr107.EhcacheCachingProvider</property>
	
	
	<!-- Uncomment this if Elastic Server is OFF -->
	<property name="hibernate.search.enabled">false</property>
	</composite-id>
	<property name="transactionStat">
		<column name="TRANS0STAT" not-null="true" length="1" />
	</property>
	<property name="mrsuid">
		<column name="MRSUID" not-null="true" length="3" />
	</property>
	<many-to-one name="TestMaster" not-null="true" class="com.test.entity.TestMaster" fetch="select" insert="false" update="false">
		<column name="LOCATION" />
		<column name="MASTER0CO" />
		<column name="SYMBOL" />
		<column name="test0NUM" />
		<column name="MODULE" />
	</many-to-one>
	<set name="comments" table="Test1" inverse="true" lazy="true" fetch="select" cascade="all" batch-size="10">
		<key>
			<column name="LOCATION" />
			<column name="test0NUM" />
			<column name="SYMBOL" />
			<column name="MASTER0CO" />
			<column name="MODULE" />
		</key>
		<one-to-many class="com.test.entity.Comment" />
	</set>
	<set name="interests" table="Test2" inverse="true" lazy="true"
		fetch="select" cascade="all" batch-size="10">
		<key>
			<column name="LOCATION" />
			<column name="test0NUM" />
			<column name="SYMBOL" />
			<column name="MASTER0CO" />
			<column name="MODULE" />
		</key>
		<one-to-many class="com.test.entity.Interest" />
	</set>

@beikov please check if you can support here -
Here I am getting some extra field like org.hibernate.collection.spi.PersistentSet
isTempSession
initialized
cachedSize
role
key
dirty
elementRemoved
storedSnapshot

Please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.

Created issue - (Jira) I am unable to create test case because of legacy code and hbm file we are using in our project.