6.5: what jdbc type for SchemaUpdate to generate text column on PostgreSQL

Hi,

While upgrading Hibernate to 6.5, I discovered a completely different behaviour of SchemaUpdate because it seems a bug was fixed (Fix SqlTypes::isStringType · hibernate/hibernate-orm@e9a7a57 · GitHub) and now SchemaUpdate is correctly checking String fields length.

My problem is that I want to have text datatype for a column in db, but I cannot manage to instruct Hibernate (using JdbcTypeCode for example) to recognize text column as having the correct length.

Right now if I use @JdbcTypeCode(SqlTypes.LONGVARCHAR) it tells me to use the type varchar(32600).

I also tried to use LONG32VARCHAR which I suspect is meant to answer that need, but the jdbc postgresql driver will fail then with this kind of error when those fields are set to null:

Caused by: org.postgresql.util.PSQLException: Unknown Types value.
	at org.postgresql.jdbc.PgPreparedStatement.setNull(PgPreparedStatement.java:297)
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.setNull(HikariProxyPreparedStatement.java)
	at io.opentelemetry.instrumentation.jdbc.internal.OpenTelemetryPreparedStatement.setNull(OpenTelemetryPreparedStatement.java:80)
	at org.hibernate.type.descriptor.jdbc.BasicBinder.doBindNull(BasicBinder.java:98)
	at org.hibernate.type.descriptor.jdbc.BasicBinder.bind(BasicBinder.java:51)
	at org.hibernate.engine.jdbc.mutation.internal.JdbcValueBindingsImpl.lambda$beforeStatement$0(JdbcValueBindingsImpl.java:87)

Please try to create a reproducer with our test case template and if you are able to reproduce the issue, create a bug ticket in our issue tracker and attach that reproducer.

Ok, I will try.

Also, I ended up using @Column(length = Length.LONG32) is that maybe a better approach than using the @JdbcTypeCode?

Here it is: [HHH-18446] - Hibernate JIRA

Also I would be curious about my other question on using @Column(length = Length.LONG32), is that the better practice?

1 Like

Thanks for the bug report. Yes, configuring the length directly is the preferred approach.

1 Like