Check condition for BooleanJavaType with Boolean converter

Hi,
I’m using Hibernate in a Spring Boot application. I’m having some issues migrating to version 6.4 due to the presence of Converters, especially with the constraint generation part. Specifically:

  1. Why are constraints always generated even if DDL generation is disabled in the configuration?
  2. I believe it should be configurable how these check condition constraints are generated. Simply put, my Converter for Boolean and Enum is not deterministic: I want to store obfuscated data in the database, and I don’t want true to always have the same value. This conflicts with the way the constraint is generated, as it does not account for this particularity. I believe this should be a behavior that can be disabled.

You can create a subclass of BooleanJavaType and register that via the @JavaTypeRegistration annotation to take effect globally. In that subtype, just always return null for the getCheckCondition method.
Note though, that a mapping that is not globally homomorphic will make it impossible to use a field of that type in a query.

Hi @beikov ,
thanks, I confirm that using a custom BooleanJavaType with @JavaTypeRegistration it works. What initially held me back from this approach is that I can’t understand why Hibernate generates constraints even though I have set generate-ddl: false and ddl-auto: none. My database already exists, so Hibernate should not be responsible for generating the database script (and consequently, not the check condition either). Why does Hibernate always generate the check conditions?

What do you mean by “always generate the check condition” exactly? Do you mean the code for generating this DDL fragment is called even though you disabled DDL generation?

Exactly. In my application, Hibernate does not generate the schema; the database is managed by Liquibase. In fact, in the configuration, I have ddl-auto: none and generate-ddl: false. However, despite this, the getCheckCondition method is called for all the entity columns whose field is a Boolean. Since this is a string used exclusively for schema creation, I can’t understand why it is necessary to call the getCheckCondition method in this case.

I guess it’s just “easier” to do that stuff this way. Please create a bug ticket in our issue tracker and link to this conversation.

Thank you @beikov
Here the issue: Jira

1 Like