Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6737417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:14:47+00:00 2026-05-26T11:14:47+00:00

I have problem with one-to-many mapping. Two tables questions(PK(id), text) and answers(PK(id, questionId), text)

  • 0

I have problem with one-to-many mapping.
Two tables questions(PK(id), text) and answers(PK(id, questionId), text)
In my app I use this tables in read-only mode.
I want define relations between this tables

@Entity
@Table(name = "QUESTIONS")
public class Question {
    @Id
    @Column(name = "QUESTIONID")
    private long questionId;
    @Column(name = "QUESTIONTEXT")
    private String questionText;
    @OneToMany(mappedBy = "question", fetch = FetchType.EAGER)
    private List<Answer> answers;         
}

@Entity
@Table(name = "ANSWERS")
public class Answer implements Serializable {

    @EmbeddedId
    private AnswerPK AnswerPK;
    @Column(name = "ANSWERTEXT")
    private String answerText;
    @ManyToOne
    @JoinColumn(name = "QUESTIONID", insertable = false, updatable = false)
    private Question question;
}

@Embeddable
public class AnswerPK implements Serializable {
    @Column(name = "QUESTIONID")
    private long questionId;
    @Column(name = "ANSWERID")
    private int answerId;
}

But when I use @JoinColumn will be created foreign key.
And when I try to fill tables, I got exception

java.sql.SQLIntegrityConstraintViolationException: ORA-02292: integrity constraint (ZODI.FK_ANSWERS_QUESTIONID) violated - child record found
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:14:48+00:00Added an answer on May 26, 2026 at 11:14 am

    Try putting the insertable/updatable=false in the EmbeddedId, not the JoinColumn.

    Also consider not using an EmbeddedId, instead use a IdClass, then you just need to annotate the answerId and the question with @Id. Or even better, remove the questionId from the primary key and ensure answerId is unique (such as making it a generated id).

    See,
    http://en.wikibooks.org/wiki/Java_Persistence/Identity_and_Sequencing#Primary_Keys_through_OneToOne_and_ManyToOne_Relationships

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem :( I have a many-many table between two tables(1&2), via
I have this problem where I have a one-to-many relationship and I have to
I have two entities, Job and Language , in a many-to-one relationship. The mapping
I have already read Entity Framework One-To-One Mapping Issues and this is not duplicate
I am having problem with my Hibernate Mapping. I have a many to one
i have one problem in one-to-many mapping using hibernate. i have 2 classes, Person
I have two classes in Grails application , Employee has hasMany(one To Many relations)
I have two related objects: ProgramSession and ProgramTask, with a one-to-many relationship. A ProgramSession
Entity Photos belongs to Property entity and one property can have many photos. Mapping
I am trying to generate a unidirectional one-to-many mapping between two JPA entities. In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.