-->

JPA configure boolean fields to persist as integer

2020-08-23 01:14发布

问题:

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.

回答1:

You can specify the column definition:

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


回答2:

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")


标签: java jpa