Session.load() javassist proxy erase type parameters on many-to-many-relations, Session.get() works.

Description

I was trying to develop a custom Spring/Hibernate Converter to automatically bind form's checkboxes tag to Hibernate's persistent entities, when I discovered this bug.

Behind the scenes, Spring use reflection to discover the element type of a collection, in order to guess the right converter for the elements in it.

Unfortunately, when one read a persistent instance via Session.load() method, the type parameter informations are lost.

You can see the complete test in the it.unipg.jira.hibernate.Test class of the attached example. To run the tests, extract the archive and run
mvn -P hibernate3 clean tests
to test Hibernate 3 and
mvn -P hibernate4 clean tests
to test Hibernate 4.

BTW, consider the JPA entity below:

Consider now the following pseudo-java code:

As you can see, if we load() the persistent instance, the proxy javassist-generated class do not inherit the type parameters informations, so we cannot the collection's generic type.

I mark this Issue as Minor because one can effectively use get() instead of load() in most situations.

Sorry for my poor english.

Environment

Hibernate 3, Hibernate 4, Spring, Javassist, HSQLDB, OpenJDK6, Linux Debian stable

Activity

Show:
Steve Ebersole
October 27, 2015, 7:14 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Steve Ebersole
October 28, 2015, 3:25 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Giulio Quaresima
October 28, 2015, 10:43 AM

OK. Here attached is the new test case:


Uncompress the archive and launch the tests with Maven. There are three Maven profiles for the three versions of hibernate which I tested (3,4,5):

The class containing the two tests is it.unipg.jira.hibernate.Test

Best regards.
Giulio Quaresima

Steve Ebersole
October 28, 2015, 11:02 AM

Thanks for verifying!

I am going to reclassify this. It is not a bug. You are asking for Hibernate something it never claimed to do. That is a feature/enhancement request, not a bug.

Assignee

Unassigned

Reporter

Giulio Quaresima

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Minor
Configure