java Hibernate:对字符串ID使用自动增量

taor4pac  于 2023-03-06  发布在  Java
关注(0)|答案(1)|浏览(156)

我想对字符串字段使用自动增量ID,如下所示:

@Id
    @GeneratedValue(strategy = TABLE, generator = "MY_GENERATOR")
    @TableGenerator(name = "NAME", table = "MY_TABLE", pkColumnName = "MY_COLUMN", pkColumnValue = "MY_REF", valueColumnName = "SOMETHING", allocationSize = 1)
    @Column(name = "COL", unique = true, nullable = false, length = 3)
    public String getFcvCval() {
        return this.fcvCval;
    }

但是我得到了一个异常类型:

org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String

我无法更改列的类型(它必须是字符串)。是否有方法将生成的数字IDMap到其字符串值?

fykwrbwg

fykwrbwg1#

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GenericGenerator(name="increment", strategy = "increment") 
private String fcvCval;

您可以像这样使用,也可以添加附加注解

相关问题