Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HHH-19017: Address ClassCastException for PersistentAttributeInterceptable #9605

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jimsimon-wk
Copy link

@jimsimon-wk jimsimon-wk commented Jan 10, 2025

A ClassCastException is thrown when trying to resolve instances without bytecode enhancement enabled under these preconditions:

Related Change in Hibernate 6.6

Reproducer


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-19107
https://hibernate.atlassian.net/browse/HHH-19017

Copy link
Member

@mbladel mbladel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jimsimon-wk! Just left a few minor comments, but other than that your change looks good to me.

Comment on lines 31 to 49
scope.inTransaction(session -> {
// Create company
Company company = new Company();
company.id = 1L;
company.name = "Hibernate";
session.persist(company);

// Create project
Project project = new Project();
project.id = 1L;
session.persist(project);

// Create employee
Employee employee = new Employee();
employee.id = 1L;
employee.company = company;
employee.projects = List.of(project);
session.persist(employee);
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we separate preparing the data for tests in a @BeforeAll method. Also an @AfterAll that cleans after the test would be great, you can simply add this:

@AfterAll
public void tearDown(SessionFactoryScope scope) {
	scope.getSessionFactory().getSchemaManager().truncateMappedObjects();
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed 5b54685

.getSingleResult();
});

// No assertions here, because this test trigger an exception with Hibernate 6.6.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just add a couple assertions verifying the returned Employee instance contains what you expect (an initialized projects collection, and the correct company association), they're not fundamental for what you're trying to fix but still they ensure consistency in the test.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed 5b54685

@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Jan 16, 2025

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@jimsimon-wk
Copy link
Author

Thanks for the helpful review @mbladel! I thought I had imported the codestyles to IntelliJ, but I must have forgotten to apply formatting. This moved things around a little in the unit test too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants