使用JPA和Hibernate将Java布尔值映射到Oracle Number列 [英] Mapping Java boolean to Oracle Number column with JPA and Hibernate

查看:104
本文介绍了使用JPA和Hibernate将Java布尔值映射到Oracle Number列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在模型中创建了一个这样的属性:

I have a property created like this in my model:

    public class Client {
        private Boolean active;
}

我的RDBMS是Oracle,并且 active 列的类型是 NUMBER(1,0).

My RDBMS is Oracle and the active column is of type NUMBER(1,0).

如何使用Restrictions API来实现以下功能?

How can I use the Restrictions API to achieve the following functionality?

criteria.add(Restrictions.eq("active"),object.isActive());

推荐答案

Hibernate自动将 Boolean Java类型映射到Oracle NUMBER(1,0).

Hibernate maps the Boolean Java type to Oracle NUMBER(1,0) automatically.

因此,您可以在实体映射,JPQL或Criteria查询中使用 Boolean 值,并且生成的SQL将改为使用数据库 NUMBER(1,0)格式

So, you can use a Boolean value in your entity mappings, JPQL or Criteria queries and the generated SQL will use the database NUMBER(1,0) format instead.

这篇关于使用JPA和Hibernate将Java布尔值映射到Oracle Number列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆