java - 如何在 hibernate hbm 文件中映射 boolean 值

标签 java hibernate

在我的数据库中,我有这样的列

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

在我的bean中,我有

    private Boolean isDefaultPaymentForCurrency;

我的问题是,如何在 hibernate hbm 文件中映射此 isDefaultPaymentForCurrency

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

最佳答案

使用

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

要使用 hql,您可以在 hibernate.cfg

中设置此属性
<property name="hibernate.query.substitutions">true 'Y', false 'N'</property>

关于java - 如何在 hibernate hbm 文件中映射 boolean 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18902205/

相关文章:

Java 正则表达式和 json

java - 在 Azure 中的存储帐户之间复制 blob - 此存储帐户错误不允许公共(public)访问

java - 使用嵌套构造函数查询

java - 不同持久化上下文中的不同 hashCode()?

mysql - 如何创建自定义方言并将其添加到 Grails 3 中的 application.yml 文件中?

java - 如何基于多个不同的 URI 构建查询

java - JInternalFrame 裁剪后的 Windows 外观和感觉

java - JSP/HTML : Trying to pass html input to multiple objects that have the same variable name for use

spring - Hibernate Search 的使用、何时使用以及为什么

java - com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException : Column cannot be null/one-to-one mapping