create table foo (id INT(10) not null ...)
我不想将 id 声明为“INTEGER”,而是像上面提到的那样指定一个长度限制。
我用
@实体 类 Foo {
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false, insertable = false, updatable = false)
private Integer id;
...
我应该如何在我的 JPA 模型类中指定长度限制,以便 hbm2ddl 根据我的要求自动生成架构。
最佳答案
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id",length=50, unique = true, nullable = false, insertable = false, updatable = false)
private Integer id;
在您的情况下,您使用的是注释/JPA。如果您使用了映射,那么可以这样使用:
<property name="id" type="Integer" length="20"/>
试试这个
关于hibernate - 如何通过 JPA 注释指定具有一定长度的整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6894514/