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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:16:34+00:00 2026-05-28T07:16:34+00:00

I am new to persistence world :) May be my question is very silly

  • 0

I am new to persistence world 🙂 May be my question is very silly and may be my approach is incorrect but that is what I want to ask some expert. So my problem is about writting a query for an entity that is related to another entity.

@Entity
public class Team {
  String teameName, 
  int teamId,

  @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  @JoinColumn(name = "team_id", referencedColumnName = "teamId")
  private Set<Player> players;
  /**
     more code for getters and setter for all fields       
  */       
}

@Entity
public class Player {
    String PlayerName,
    String address 
    /**
     *more code for getters and setter for everything       
    */
}

So multiple player can belong to one team but every player must have a unique Team which is done with making teamId as a foreign key to Player.
As far as I can think this should be correct.But now comes the problem.
Now I want to make a query to find all the players with “playerName=X” and “teamId =Y”
And I have no idea how to write such query.

Please can anyone suggest me something.

Thanks in advance.

Jeena

  • 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-28T07:16:34+00:00Added an answer on May 28, 2026 at 7:16 am

    You want to read about HQL, the Hibernate Query Language. It’s kind of like SQL.

    Basically you define you hql string, and then execute the query. Something like

    String hql = "select * from Player p where p.PlayerName = :name and team = :team";
    Query query = session.createQuery(hql);
    query.setParameter("name", "Joe");
    query.setParameter("team", team);
    List list = query.list();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to the world of ORMs/ODMs. The word 'persistence' is used often. What
We're working on a new system that uses hibernate for persistence. As the schema
How would I achieve something along the lines of this.. var Persistence = new
I am new to Java Persistence API . I have just learnt it and
I need a tabbed application with core data persistence. when i create a new
new on ruby and using windows xp and rails 3, i want to send
New to Regex. I want to validate to this format: Any character allowed, except
new here and new to jQuery. I've searched for an answer to my question/
This is more of an opinion seeking question, so there may not be a
I am new in web development world (from microcontrollers to web is a really

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.