本文介绍了我怎样才能使用组合键内产生价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个类documentlog和documentversion(与主键:INT DOC_ID和int docVersionID)与多到一的关系。我使用了一种名为CompundKey复合键类来管理的复合主键。我需要自动增量docversionID,但我不能这样做。能否请你帮我在这方面?
@Entity
@Table(NAME =Documentversion,模式=DocumentManagement)
公共类DocumentVersion实现Serializable { 私人CompoundKey ID;
私人列表< DocumentLog> documentLog; @OneToMany(的mappedBy =documentVersion,targetEntity = DocumentLog.class,
级联= {CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH})
公开名单< DocumentLog> getDocumentLog(){
返回documentLog;
}
公共无效setDocumentLog(列表< DocumentLog> documentLog){
this.documentLog = documentLog;
} @EmbeddedId
@AttributeOverride(NAME =DOC_ID,列= @列(名称=DOC_ID))
公共CompoundKey的getId(){
返回ID;
}
公共无效SETID(CompoundKey ID){
this.id = ID;
}
}
解决方案
该文档是关于该主题...
有点混乱据我所知,组合键总是要的分配的应用程序(即非生成的)至少与标准JPA也是Hibernate的核心:
But things might be a bit different in practice (see HHH-2060 and/or this thread for an alternative using a CompositeUserType together with an IdentifierGenerator).
Now, the most confusing part, from the Hibernate Annotations 3.5 documentation:
(and please also read the warning from the Hibernate Team against using this feature).
I don't have any practical experience with it though.
References
- Hibernate Core Reference Guide
- Hibernate Annotations 3.5 Reference Guide
这篇关于我怎样才能使用组合键内产生价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!