休眠关系
我有一个如下所示的表模型:
@Entity
@Table(name="RULEADMIN_QUESTIONNAIRE")
public class Questionnaire {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "QUESTID")
private long questionID;
@Column(name = "QUESTION")
private String question;
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "QUESTORDER")
private long questionOrder;
@Column(name = "QUESTCATEGORYID")
private long questionCatgoryID;
@Column(name = "QUESTREFERENCESTRING")
private String questionReferenceString;
@Column(name = "ACTIVEFLAG")
private long activeFlag;
@Column(name = "LASTMODUSERID")
private long lastModifiedUserID;
@Column(name = "LASTMODDATE")
private Date lastModifiedDate;
@OneToMany(cascade=CascadeType.ALL)
@JoinColumn(name="QUESTID")
@Transient
private List<QuestionAnswerOption> questionAnswerOptions;
public Questionnaire() {
}
.....list of setters and getters
}
这里 QUESTID
和 QUESTORDER
将具有相同的值,QUESTID
将自动生成。但我也希望 QUESTORDER 具有相同的值,因为两者都具有相同的值。我尝试通过注释 @GenerateValue(strategy=GenerationType.AUTO) 但它没有获取值。我怎样才能将 QUESTID
获取到 QUESTORDER
?
I have a table model like below:
@Entity
@Table(name="RULEADMIN_QUESTIONNAIRE")
public class Questionnaire {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "QUESTID")
private long questionID;
@Column(name = "QUESTION")
private String question;
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "QUESTORDER")
private long questionOrder;
@Column(name = "QUESTCATEGORYID")
private long questionCatgoryID;
@Column(name = "QUESTREFERENCESTRING")
private String questionReferenceString;
@Column(name = "ACTIVEFLAG")
private long activeFlag;
@Column(name = "LASTMODUSERID")
private long lastModifiedUserID;
@Column(name = "LASTMODDATE")
private Date lastModifiedDate;
@OneToMany(cascade=CascadeType.ALL)
@JoinColumn(name="QUESTID")
@Transient
private List<QuestionAnswerOption> questionAnswerOptions;
public Questionnaire() {
}
.....list of setters and getters
}
Here QUESTID
and QUESTORDER
will have the same value, QUESTID
will get generated automatically. But I want the same value for QUESTORDER
also, because both will have the same value. I have tried by annotating @GeneratedValue(strategy=GenerationType.AUTO)
but it is not getting the value. How can I get the QUESTID
to QUESTORDER
also?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这没有多大意义,如果有一个令人信服的理由(一些依赖的遗留代码?)有两个相同的字段,我会这样做:
This doesn't make much sense, if there is a compelling reason (some dependent legacy code?) to have two fields that are identical I would do it like this: