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

HibernateTypesContributor does not register Types on Hibernate 5 and 4 for Oracle, SQL Server, and PostgreSQL #441

Closed
SergeiKhmelevSPA opened this issue Jun 2, 2022 · 11 comments · Fixed by #442
Assignees
Labels
Milestone

Comments

@SergeiKhmelevSPA
Copy link
Contributor

Hibernate ORM core version: 5.6.8.Final
Hibernate Types 55 version: 2.16.2

During Spring Boot context creation MetadataBuildingProcess handles types provided via TypeContributor. So com.vladmihalcea.hibernate.type.HibernateTypesContributor also tries to contribute types. The problem is that it couldn't do it for Postgres because of the condition

// org.hibernate.dialect.PostgreSQLDialect
if(dialect instanceof PostgreSQLDialect)

PostgreSQLDialect is deprecated and PostgreSQL82Dialect should be used instead.

@SergeiKhmelevSPA
Copy link
Contributor Author

And a question related to it. I tried to test contributeType() locally, but it doesn't seem to do anything. Eg. I still have to use

class CustomPostgresDialect : PostgreSQL10Dialect() {
	init {
		this.registerHibernateType(2003, StringArrayType::class.java.name)
	}
}

to allow support for StringArrayType for projections. To be honest, I expected it from contributeType(typeContributions, StringArrayType.INSTANCE).

@vladmihalcea
Copy link
Owner

Thanks for the tip. The PostgreSQLDialect is the default one in Hibernate 6, and I forgot to change it for 55.

@vladmihalcea vladmihalcea self-assigned this Jun 2, 2022
@vladmihalcea vladmihalcea added this to the 2.16.3 milestone Jun 2, 2022
SergeiKhmelevSPA added a commit to SergeiKhmelevSPA/hibernate-types that referenced this issue Jun 3, 2022
@SergeiKhmelevSPA
Copy link
Contributor Author

By the way, I noticed the same issue with OracleDialect

@vladmihalcea vladmihalcea changed the title HibernateTypesContributor is not register any types for Postgres HibernateTypesContributor does not register Types on Postgres on Hibernate 5 and 4 Jun 3, 2022
@vladmihalcea
Copy link
Owner

Don't worry, I'll amend the commit for Oracle and/or SQL Server too

@vladmihalcea vladmihalcea changed the title HibernateTypesContributor does not register Types on Postgres on Hibernate 5 and 4 HibernateTypesContributor does not register Types on Hibernate 5 and 4 for Dialects that don't match the base one in Hibernate 6 Jun 3, 2022
@vladmihalcea vladmihalcea changed the title HibernateTypesContributor does not register Types on Hibernate 5 and 4 for Dialects that don't match the base one in Hibernate 6 HibernateTypesContributor does not register Types on Hibernate 5 and 4 for Oracle, SQL Server, and PostgreSQL Jun 3, 2022
vladmihalcea pushed a commit that referenced this issue Jun 3, 2022
@stevefranchak
Copy link

When might it be expected for 2.16.3 to be released? I'm unable to use hibernate-types until it is due to this issue.

@vladmihalcea
Copy link
Owner

vladmihalcea commented Jun 24, 2022

I released the 2.16.3 version that features this fix.

@victornoel
Copy link

Hello @vladmihalcea, I am hitting a small issue with this fix: in my codebase, I am using version 2.16.2 and I never really realized that HibernateTypesContributor wasn't properly registering types for PostgreSQL (it seems it never was a problem when using json types).

I have legacy code that is using String[] as a type for a columns and is currently persisted as bytea in the db (this is the default behavior of hibernate 5.6 apparently).

I upgraded to 2.16.3 (because of the serialization issue from #438) and now, StringArrayType being properly registered, hibernate tries to persist my String[] column as a text[].

How would I go about disabling this only for that column?

Thank you, I hope it's ok to ask this here :)

@vladmihalcea
Copy link
Owner

First, Hibernate Types 2 is an ancient version. Thr project is called Hypersistence Utils and the latest version is 3.5.3.

Second, I no longer have the time to offer free support for this library. I only offer support via consulting.

@victornoel
Copy link

@vladmihalcea ok, thank you in any case for this great library :)

@vladmihalcea
Copy link
Owner

You're welcome.

@victornoel
Copy link

For anybody coming through here looking for the answer to my question, the solution was to force the type of the column to SerializableType as it seems to be the fallback Hibernate uses to persist String[]:

@Basic
@Type(type = "serializable")
private String[] column;

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

Successfully merging a pull request may close this issue.

4 participants