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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:27:31+00:00 2026-06-17T07:27:31+00:00

I am using: Spring 3.2 Hibernate 4.1.9 I need to map, with JPA, three

  • 0

I am using:
Spring 3.2
Hibernate 4.1.9

I need to map, with JPA, three classes. Class A has a ManyToMany relationship with Class B. A unique combination of Class A and Class B need to own a collection of Class C.

Table A

foo
id | name

Table B

bar
id | name

Table C

data
id | xrefId

Join Table — Unique Key on (fooId,barId)

xref
id | fooId | barId

Altering the existing data structure is not an option.

Edit 1:

Goal: Load a Foo, get its collection of Bars. From each Bar, get its (their!) collection of Data.

Class A

@Entity
public class Foo {
  @Id
  private UUID id;

  @ManyToMany(optional = false)
  @JoinTable(name               = "xref",
             joinColumns        = { @JoinColumn(name = "fooId") },
             inverseJoinColumns = { @JoinColumn(name = "barId") })
  private List<Bar> lstBar = new ArrayList<Bar>();
}

Class B

public class Bar {
  @Id
  private UUID id;

  @ManyToMany(mappedBy = "lstBar")
  private List<Foo> lstFoo = new ArrayList<Foo>();
}

Class C

public class Data {
  @Id
  private UUID id;
}
  • 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-17T07:27:32+00:00Added an answer on June 17, 2026 at 7:27 am

    Just KISS. Make another class Xref, which contains id, foo, bar and Set<Data> fields. Make a DAO method to find an Xref using two parameters foo and bar (implement it with a simple HQL). The unique requirement could be achieved by an unique constraint in the database.

    It doesn’t look good trying to express it just by the class hierarchy, better to use DAOs.

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

Sidebar

Related Questions

I am developing a Java Web Application using JSF, Spring and Hibernate. I need
I'm using Spring with Hibernate as a JPA provider and are trying to get
I am using Spring MVC with Hibernate. My page has a button that creates
Using Fluent NHibernate I need a clue how to map my Invoice class. public
Using spring-batch and JPA (provided by hibernate). I have a step that does the
I'm using Spring 3.1.1.RELEASE, Hibernate 4.1.0.Final, JPA 2, JUnit 4.8.1, and HSQL 2.2.7. I
I'm working with Spring/Hibernate (using NetBeans 6.9.1). I need to import Excel sheet into
I'm using Spring with Hibernate. I have some queries that don't actually need a
I am developping a web application using Spring (3.1.x), JSF 2, JPA 2 (Hibernate
I am using spring/hibernate stand alone application. if i dont configure Transactions i am

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.