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 8665415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:28:36+00:00 2026-06-12T17:28:36+00:00

I have a many-to-many relationship were the link table has an additional field. Hence

  • 0

I have a many-to-many relationship were the link table has an additional field. Hence the relationship is done with 2 one-to-many relations according to below tutorial:

http://www.mkyong.com/hibernate/hibernate-many-to-many-example-join-table-extra-column-annotation/comment-page-1/#comment-122181

I have the 2 entities, a third entity which defined the link table and consist of an @Embeddable ID field.

The relationship is defined as:

@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.compound", cascade = CascadeType.ALL)

@OneToMany(fetch = FetchType.LAZY, mappedBy = "pk.structure", cascade = CascadeType.ALL)

were pk = the @Embeddable ID field. Insert and deleting works fine however when I call

session.merge(compound);

I get a StackOverflowError and log shows that hibernate is making tons of select statements. Note that database contains exactly 1 association, eg. 1 compound containing 2 structures. It looks like hibernate gets into a endless loop.

I’ve seen this solution also on http://giannigar.wordpress.com/2009/09/04/mapping-a-many-to-many-join-table-with-extra-column-using-jpa/ but how do you do updated with this?

  • 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-12T17:28:37+00:00Added an answer on June 12, 2026 at 5:28 pm

    My solution was to use FetctType.EAGER on the owning side and FetchType.Lazy on child side and in the 2 ManyToOne relations in the link table. Like this I can load from the owning side without getting LazyInitializationException and mergign working as expected.

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

Sidebar

Related Questions

I have a many-to-many relationship with a link box, and I want to pull
I have a many-to-many relationship with a weight factor column in the bridge table
I have a many-to-many relationship between users and groups and I have a table
I have a many to many relationship: Product has many Categories and Category has
I have two domains in a Grails application with a one-to-many relationship: Course and
Is it possible to have a has and belongs to many relationship in active
I have a relationship table with followed_id, follower_id, and status. I am using has
We have a link table that can handle multiple types of object on one
I have many to many relationship in entity framework. See image... I want to
I have a many-to-many relationship in my django application where I use the add

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.