简体   繁体   中英

hibernate type yes_no with 'J' instead of 'Y'

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM