从hibernate 4.3迁移到hibernate 5时遇到了一些问题。 我正在开发一个主要项目,我们使用SequenceHiLoGenerator来生成现在已弃用的id。如何在没有重大变化的情况下更新此内容?
这是我的hibernate 4.3代码。
public class KSequenceGenerator extends SequenceHiLoGenerator {
@Override
public Serializable generate(SessionImplementor session, Object object) throws HibernateException {
Serializable id = session.getEntityPersister(null, object).getClassMetadata().getIdentifier(object, session);
return id != null ? id : super.generate(session, object);
}
在EJB中:
@GenericGenerator(name="id_gen", strategy="com.or.nk.ob.base.KSequenceGenerator", parameters = {@org.hibernate.annotations.Parameter(name = KSequenceGenerator.SEQUENCE, value = "building_id_seq")})
现在我有:
public class KSequenceGenerator extends SequenceStyleGenerator {
public static final String SEQUENCE = "sequence";
@Override public Serializable generate(SharedSessionContractImplementor session, Object object) throws HibernateException {
Serializable id = session.getEntityPersister(null, object).getClassMetadata().getIdentifier(object, session);
return id != null ? id : super.generate(session, object);
}
}
ID:
@Id
@Column(name = "ID")
@GeneratedValue(generator = "id_gen", strategy = GenerationType.SEQUENCE)
public Long getId() {
return id;
}