【发布时间】:2011-05-12 13:09:21
【问题描述】:
我想根据数据库中已有的值为对象生成自定义 ID。
我知道有人就该主题提出了几个问题,但我无法找到解决方案...
这是我的课:
@Entity
class A {
// primary key for table
@GeneratedValue
@Id
private long tableId;
// id -> should be generated as (1+ (max id of type 'type'))
@Formula("1+(select t.id from mytable t where t.type=type)")
private long id;
// type
private String type;
}
我想到了@Formula注解,但我无法让它工作......
引发异常:
java.sql.SQLException: 字段 'id' 没有默认值
我不确定@Formula 是不是好的解决方案...
有人知道我如何使它工作吗?
非常感谢,
本
【问题讨论】:
标签: java hibernate jpa annotations