java JPA 配置布尔字段以保留为整数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3988046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 04:16:35  来源:igfitidea点击:

JPA configure boolean fields to persist as integers

javajpa

提问by Joel

In JPA is there an annotation to specify that boolean fields should be persisted as an integer. I'm using OpenJPA and it's currently persisting boolean fields as bits. I'd rather use integer 1 or 0.

在 JPA 中有一个注释来指定布尔字段应该作为整数持久化。我正在使用 OpenJPA,它目前将布尔字段作为位持久化。我宁愿使用整数 1 或 0。

回答by Bozho

You can specify the column definition:

您可以指定列定义:

@Column(name="boolColumn",
     columnDefinition="INT(1)")

回答by grep

You can use the following annotation:

您可以使用以下注释:

@Type(type="numeric_boolean")

If you want to write Y and N instead of 0, 1, you can use

如果你想写Y和N而不是0、1,你可以使用

@Type(type="yes_no")