Reputation: 103397
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"/>
Upvotes: 7
Views: 10186
Reputation: 18368
I refer the link, Hibernate Mapping Types, and use boolean
finally.
A hbm.xml
example.
<property name="scheduable" type="boolean" >
<column name="SCHEDUABLE" not-null="true" default="false" />
</property>
Upvotes: 3
Reputation: 909
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
Upvotes: 3
Reputation: 14413
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>
Upvotes: 3
Reputation: 11486
You may want to try the following type: org.hibernate.type.YesNoType
. The following reference may be used for this (in particular section 6.1.1.3). Registered as yes_no
Upvotes: 0