Hi ,
After migrating to Hibernate 6.6.13.Final from 5.6.x, we are seeing below errors. Same code was working fine before. Please note that it works after adding @Transactional annotation, which was not needed previously. Also if i apply below properties in my data-source config, it works fine without @Transactional. My issue is that i need to add @Transaction in 100+ places which i want to avoid now. Please suggest. It is complaining about oneToMany association which is “lazy” loading option.
ERROR AssertionFailure HHH000099: an assertion failure occurred (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: collection owner not associated with session
downgradeHoldCursorsUnderXa=true
resultSetHoldability=1
Hi All,
Can someone please provide more details regarding below? How to make it version 5 equivalent? Is there a property i can set?
In Hibernate 6, the behavior around “hold cursor” (specifically, the holdCursorBeforeUpdate
property) has changed. In Hibernate 6, this property, by default, is no longer true. Hibernate 6 defaults to closing the cursor after the transaction. This change can affect applications that rely on maintaining a cursor open for updates or other operations.
Thanks
Hello @Sanjay3, another user reported a similar problem when using DB2, an XA datasource with auto-commit enabled, and using Hibernate without a transaction. This isa known issue of the DB2 JDBC driver:
Basically, DB2’s JDBC driver is automatically configured to close cursors on commit. This causes the new query logic in Hibernate 6, which can open multiple ResultSet
s to initialize nested-associations, to encounter problems when closing the first one.
Other than setting the 2 properties your already found, the only viable alternative is to open a transaction (as you already figured out using @Transactional
) when doing query operations. Note that since auto-commit
is enabled, the database is opening a new transaction for every statement automatically anyway, so this is simply causing more operations to be executed. Using a single transaction is easy and will also probably improve performance, so that would be our suggestion.
Hi Marco, Thanks for the response. Do you expect any performance issue with 2 variables?
downgradeHoldCursorsUnderXa=true
resultSetHoldability=1
That really depends on your use-case. The best way to avoid this problem is to disable auto-commit, or if you want to keep using it, properly use transactions even when simply retrieving data from the database. That will result in better performance as you won’t need to open and close the result set for every statement that gets executed.
The configuration properties are a workaround and should not impact performance negatively most of the time, but I cannot tell you for sure if it’s going to impact your specific use case.
1 Like