JPA configure boolean fields to persist as integer

2020-08-23 01:17发布

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.

标签: java jpa
2条回答
仙女界的扛把子
2楼-- · 2020-08-23 01:43

You can specify the column definition:

@Column(name="boolColumn",
     columnDefinition="INT(1)")
查看更多
走好不送
3楼-- · 2020-08-23 01:43

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

@Type(type="yes_no")
查看更多
登录 后发表回答