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

  • Home
  • SEARCH
  • 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 8986603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:35:22+00:00 2026-06-15T21:35:22+00:00

I’m using JPA annotations only and hibernate 4.0.1 as the JPA implementation. I have

  • 0

I’m using JPA annotations only and hibernate 4.0.1 as the JPA implementation.

I have anAssessmentclass that has two sets of Comment:

@Entity
@Table(name = "ASSESSMENT")
public class Assessment{

    @OneToMany(fetch = FetchType.EAGER)
    private Set<Comment> auditComments = new HashSet<Comment>();

    @OneToMany(fetch = FetchType.EAGER)
    private Set<Comment> comments = new HashSet<Comment>();
}

(I’m skipping getters, setters, cascade annotations and other irrelevant lines of code)

Comment:

@Entity
@Table(name = "COMMENT")
public class Comment{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(columnDefinition = "text")
    private String text;
}

Now, because a Comment doesn’t have a reference back to Assessment (this is on purpose), I cannot uset the mappedBy property and Hibernate needs to create a mapping table between Comment and Assessment. By default, it is named ASSESSMENT_COMMENT.

If I had only one set of Comment in Assessment, that would work perfectly fine. The ASSESSMENT_COMMENT would have only two columns:

[ASSESSMENT_ID, COMMENT_ID]

which will perfectly represent the one-to-many relationship.

Now here is the problem:

Because I don’t have one set of Comment but two, Hibernate tries to map the two sets using only one ASSESSMENT_COMMENT table. This table has 3 columns:

[ASSESSMENT_ID, COMMENT_ID, AUDITCOMMENT_ID]

On top of that, the 3 columns are set as non nullable.

That certainly cannot work. For instance, if I have only one item in auditComents and none in comments, hibernate tries to insert one row with a null in COMMENT_ID which creates a SQL exception.

Questions:

To me it looks like a bug. There should be two mapping tables, not one.

So, 1) is it a known bug in Hibernate? 2) is there a way around that? Can I force Hibernate to create two mapping tables, one for each of the set. Bear in mind that I cannot change the Comment class to have a reference to Assessment (business logic requirement)

  • 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-06-15T21:35:23+00:00Added an answer on June 15, 2026 at 9:35 pm

    First of all, you could use two columns in the comment table to point back to their assessment:

    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "audit_commented_assessment_id")
    private Set<Comment> auditComments = new HashSet<Comment>();
    
    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "commented_assessment_id")
    private Set<Comment> comments = new HashSet<Comment>();
    

    If you want two join tables, the just say so:

    @OneToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "assessment_audit_comment",
               joinColumns = @JoinColumn(name = "assessment_id"),
               inverseJoinColumns = @JoinColumn(name = "comment_id"))
    private Set<Comment> auditComments = new HashSet<Comment>();
    
    @OneToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "assessment_comment",
               joinColumns = @JoinColumn(name = "assessment_id"),
               inverseJoinColumns = @JoinColumn(name = "comment_id"))
    private Set<Comment> comments = new HashSet<Comment>();
    

    That is of course explained in the documentation.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I have a French site that I want to parse, but am running into
I have an array which has BIG numbers and small numbers in it. I
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.