休眠关系

发布于 2024-12-10 17:46:59 字数 1273 浏览 0 评论 0原文

我有一个如下所示的表模型:

@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
}

这里 QUESTIDQUESTORDER 将具有相同的值,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染年凉城似染瑾 2024-12-17 17:46:59

这没有多大意义,如果有一个令人信服的理由(一些依赖的遗留代码?)有两个相同的字段,我会这样做:

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "QUESTID")
private long questionID;

public long getQuestionId(){
  return this.questionID;
};

public long getQuestionOrder(){
  return getQuestionID();
};

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:

@Id
@GeneratedValue(strategy=GenerationType.AUTO)
@Column(name = "QUESTID")
private long questionID;

public long getQuestionId(){
  return this.questionID;
};

public long getQuestionOrder(){
  return getQuestionID();
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文