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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:19:09+00:00 2026-05-18T02:19:09+00:00

Given the following entity (some columns omitted from this long definition for brevity): @Table(name

  • 0

Given the following entity (some columns omitted from this long definition for brevity):

@Table(name = "Products")
public class Products implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "SKU")
    private String sku;
    @Basic(optional = false)
    @Column(name = "ProductName")
    private String productName;

    private boolean allowPreOrder;
    @ManyToMany(mappedBy = "productsCollection")
    private Collection<Categories> categoriesCollection;
    @JoinTable(name = "Products_CrossSell", joinColumns = {
        @JoinColumn(name = "SKU", referencedColumnName = "SKU")}, inverseJoinColumns = {
        @JoinColumn(name = "CrossSKU", referencedColumnName = "SKU")})
    @ManyToMany
    private Collection<Products> productsCollection;
    @ManyToMany(mappedBy = "productsCollection")
    private Collection<Products> productsCollection1;
    @JoinTable(name = "Products_Related", joinColumns = {
        @JoinColumn(name = "SKU", referencedColumnName = "SKU")}, inverseJoinColumns = {
        @JoinColumn(name = "RelatedSKU", referencedColumnName = "SKU")})
    @ManyToMany
    private Collection<Products> productsCollection2;
    @ManyToMany(mappedBy = "productsCollection2")
    private Collection<Products> productsCollection3;

How do I get the set of related products for a given product SKU?

The products_related table looks like this:

alt text

I know how to get the answer using SQL but I’m new to JPA so I haven’t quite grokked the API and query syntax yet.

  • 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-18T02:19:10+00:00Added an answer on May 18, 2026 at 2:19 am

    It seems to me there are some unnecessary collections defined. Anyway:

    @JoinTable(name = "Products_Related", joinColumns = {
        @JoinColumn(name = "SKU", referencedColumnName = "SKU")}, inverseJoinColumns = {
        @JoinColumn(name = "RelatedSKU", referencedColumnName = "SKU")})
    @ManyToMany
    private Collection<Products> productsCollection2;
    

    This piece (it is present in your code) should give you the desired products. Just rename it to relatedProducts, and the respective setter/getter.

    Update: You can get the object by:

    Product p = entityManager.find(Product.class, yourProductId);
    p.getRelatedProducts();
    

    Obtaining the entity manager depends on your setup, and a better place to look for how to obtain it, is a tutorial.

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

Sidebar

Related Questions

Given the following: declare @a table ( pkid int, value int ) declare @b
I'm stuck with a query I need to write. Given the following model: public
My entity name is "Contact" and my table name is "Contact". However, the default
Given the following Core Data Model: -> : to-one releationship ->>: to-many relationship Entity
@Entity public class Person { @ElementCollection @CollectionTable(name = PERSON_LOCATIONS, joinColumns = @JoinColumn(name = PERSON_ID))
Given following Ruby statements: (Read input and store each word in array removing spaces
Given the following XML: <current> <login_name>jd</login_name> </current> <people> <person> <first>John</first> <last>Doe</last> <login_name>jd</login_name> </preson> <person>
Given the following: List<List<Option>> optionLists; what would be a quick way to determine the
Given the following example, why do I have to explicitly use the statement b->A::DoSomething()
Given the following XML structure <html> <body> <div> <span>Test: Text2</span> </div> <div> <span>Test: Text3</span>

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.