问题描述:

I have to map a character(1) field in the database to a gorm attribute.

The field in the database is clearly a "yes_no" type, but with the exception, that the 'Y' should have the german expression 'J'.

Is there a way to handle it, or should I use a char field instead of a boolean in my gorm-class?

Thanks in advance,

网友答案:

As discussed here:

  • 14.10. Expressions

We can use configuration setting:

Booleans can be easily used in expressions by declaring HQL query substitutions in Hibernate configuration:

<property name="hibernate.query.substitutions">true 1, false 0</property>

This will replace the keywords true and false with the literals 1 and 0 in the translated SQL from this HQL:

from Cat cat where cat.alive = true

As far as I know one of these options should be:

<property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>

so you should try:

<property name="query.substitutions">true 1, false 0, yes 'J', no 'N'</property>
网友答案:

I solved this issue with a Custom-User-Type which uses a boolean type in the grails/gorm domain class and the 'J'/'N' representation on the database side.

Prepared a github rep under:

grails-gorm-ja_nein_type

相关阅读:
Top