Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map boolean in hibernate hbm file

Tags:

java

hibernate

In my database, i have column like

"ISDEFAULTPAYMENTFORCURRENCY" CHAR(1 BYTE) NOT NULL ENABLE,
CHECK (ISDEFAULTPAYMENTFORCURRENCY IN ('N','Y')) ENABLE,

In my bean, i have

    private Boolean isDefaultPaymentForCurrency;

my question, how can i map this isDefaultPaymentForCurrency in hibernate hbm file?

<property name="isDefaultPaymentForCurrency" type="???" column="ISDEFAULTPAYMENTFORCURRENCY" not-null="true"/>
like image 545
Rachel Avatar asked Sep 19 '13 18:09

Rachel


2 Answers

Use

<property name="isDefaultPaymentForCurrency"  type="yes_no" column="ISDEFAULTPAYMENTFORCURRENCY" not-null="true"/>

And to use hql you can set this property in hibernate.cfg

<property name="hibernate.query.substitutions">true 'Y', false 'N'</property>
like image 66
nachokk Avatar answered Sep 22 '22 00:09

nachokk


Type mappings from Java primitives or wrapper classes to appropriate (vendor-specific) SQL column types. boolean, yes_no, and true_false are all alternative encodings for a Java boolean or java.lang.Boolean.

http://docs.jboss.org/hibernate/stable/core.old/reference/en/html/mapping-types.html

like image 28
cvsr.sarma Avatar answered Sep 19 '22 00:09

cvsr.sarma