配置休眠(使用JPA)来存储布尔类型的Y / N而不是0/1 [英] Configure hibernate (using JPA) to store Y/N for type Boolean instead of 0/1

查看:463
本文介绍了配置休眠(使用JPA)来存储布尔类型的Y / N而不是0/1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以设置JPA / hibernate将布尔类型保存为 Y / N 吗?在数据库中(该列被定义为 varchar2(1)。它当前将它们存储为 0/1 。数据库是Oracle。

Can I setup JPA/hibernate to persist Boolean types as Y/N? In the database (the column is defined as varchar2(1). It currently stores them as 0/1. The database is Oracle.

推荐答案

我想出了如何做到这一点的唯一方法是为我的类提供两个属性。一个是编程API的布尔值,它不包含在映射中,它是getter和setter引用一个私有char变量,它是Y / N,然后我有另一个包含在hibernate映射中的protected属性,它是getters和setters引用私人字符变量直接。

The only way I've figured out how to do this is to have two properties for my class. One as the boolean for the programming API which is not included in the mapping. It's getter and setter reference a private char variable which is Y/N. I then have another protected property which is included in the hibernate mapping and it's getters and setters reference the private char variable directly.

这篇关于配置休眠(使用JPA)来存储布尔类型的Y / N而不是0/1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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