如何将主键Long id = new java.util.Date()。getTime()设置为@GeneratedValue?
我的代码:
private Long id;
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
@Column(nullable = false, name = "id")
public Long getId() {
return id;
}
感谢。
答案 0 :(得分:2)
你尝试使用自定义生成器,比如;
package x.y.z;
public class LongGenerator implements IdentifierGenerator {
@Override
public Serializable generate(final SessionImplementor sessionImplementor, final Object object) throws HibernateException {
return new java.util.Date().getTime();
}
}
和
private Long id;
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "x.y.z.LongGenerator")
@Column(nullable = false, name = "id")
public Long getId() {
return id;
}