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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:37:30+00:00 2026-06-11T11:37:30+00:00

I have two domain objects like below User.java Public class User{ private int userId;

  • 0

I have two domain objects like below

User.java

Public class User{

     private int userId;

     private String emailId;  

    private Product product; 

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PRODUCT_ID")
    public Product getProduct() {
        return this.product;
    } 
}

Product.java

public class Product{

    @Id
    @GeneratedValue 
    @Column(name = "PRODUCT_ID", unique = true, nullable = false)
    private productid;
}

In this scenario User to Product has Many-to-One relation.A multiple user can subscribe to same product.I wanted to query for user Email Ids in the User table with productId which is primary key in the Product table and foriegn key in the User table by joining those two tables..How can do that using hibernate query language or Criteria by joining those two tables?

  • 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-11T11:37:31+00:00Added an answer on June 11, 2026 at 11:37 am

    In hql you dont need to define the join columns like you do in sql by using the “on” keyword.
    You already defined the join keys in the mapping , so hibernate will do the join based on them.

    So in your case
    Select u.emailid from user u where u.product.productid = your product id.

    For more read on hql and you also should read about named queries

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

Sidebar

Related Questions

Say I have two domain objects and a mapper interface. class Person { int
I have two domain classes. class BillingServiceGroup { Integer billingServiceGroupCode String billingServiceGrpDesc String status
I have a list like this Dim emailList as new List(Of String) emailList.Add(one@domain.com) emailList.Add(two@domain.com)
Suppose I have two domain objects, Document and Author Class Document { Author author
I have two domain objects: Customer CustomerConfig Customer has a 1-1 association with CustomerConfig.
For example, we have two domain objects: Cell and Body (as in human cell
I have two Eclipse Maven Java projects. A domain project that is laden with
I've got a grails domain class I have to persist in Redis, something like
I have a an object stored in the model called domain, which has two
I have two domain classes (getter setter of two tables): Contact Information and Address

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.