我寫我自己的IdGenerator:休眠:手動調用SequenceGenerator?
public class AkteIdGenerator implements IdentifierGenerator {
public Serializable generate(SessionImplementor session, Object object)
throws HibernateException {
// if custom id is set -> use this id
if (object instanceof SomeBean) {
SomeBean someBean = (SomeBean) object;
Long customId = someBean.getCustomId();
if (customId != 0) {
return customId;
}
}
// otherwise --> call the SequenceGenerator manually
SequenceStyleGenerator sequenceGenerator ...
}
}
有誰知道我怎麼會從我的生成器類調用sequenceGenerator我通常可以每註解定義:
@GeneratedValue(
strategy = GenerationType.SEQUENCE,
generator = "MY_SEQUENCE")
@SequenceGenerator(
allocationSize = 1,
name = "MY_SEQUENCE",
sequenceName = "MY_SEQUENCE_NAME")
我會非常感激任何解決方案!
非常感謝,諾伯特