Skip to content

Conversation

@gildur
Copy link
Contributor

@gildur gildur commented Sep 2, 2024

HHH-18551 Fix memory leak caused by creation of new BasicTypeImpl on every call to getRecommendedJdbcType


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.


@quaff
Copy link
Contributor

quaff commented Sep 3, 2024

BasicTypeImpl should implements hashCode/equals also.

@gildur
Copy link
Contributor Author

gildur commented Sep 3, 2024

BasicTypeImpl should implements hashCode/equals also.

Every instance of BasicTypeImpl have different name:

	private static int count;

	private final String name;

	public BasicTypeImpl(JavaType<J> jtd, JdbcType std) {
		super( std, jtd );
		name = String.format(
				Locale.ROOT,
				"%s@%s(%s,%s)",
				EXTERNALIZED_PREFIX,
				++count,
				jtd.getJavaTypeClass().getName(),
				std.getDefaultSqlTypeCode()
		);
	}

so implementing equals/hashCode with name included would not make any difference.

@quaff
Copy link
Contributor

quaff commented Sep 4, 2024

BasicTypeImpl should implements hashCode/equals also.

Every instance of BasicTypeImpl have different name:

	private static int count;

	private final String name;

	public BasicTypeImpl(JavaType<J> jtd, JdbcType std) {
		super( std, jtd );
		name = String.format(
				Locale.ROOT,
				"%s@%s(%s,%s)",
				EXTERNALIZED_PREFIX,
				++count,
				jtd.getJavaTypeClass().getName(),
				std.getDefaultSqlTypeCode()
		);
	}

so implementing equals/hashCode with name included would not make any difference.

I don't understand why they must have different names if JavaType and JdbcType are same, maybe equals/hashCode should exclude name.

@gildur
Copy link
Contributor Author

gildur commented Sep 4, 2024

@beikov Please review

@beikov
Copy link
Member

beikov commented Sep 18, 2024

Can you please also replace the construction of BasicType with resolving in?

  • org.hibernate.sql.exec.internal.AbstractJdbcParameter#createEnumType
  • org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder#resolveInferredType

@hibernate-github-bot
Copy link

hibernate-github-bot bot commented Sep 18, 2024

Thanks for your pull request!

This pull request appears to follow the contribution rules.

› This message was automatically generated.

@beikov
Copy link
Member

beikov commented Sep 18, 2024

Please rebase and squash to a single commit.

@beikov beikov merged commit b179881 into hibernate:main Sep 18, 2024
19 of 20 checks passed
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.

3 participants