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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:48:45+00:00 2026-06-13T14:48:45+00:00

I have 2 models with a @OneToOne relationship. Let’s say a model User and

  • 0

I have 2 models with a @OneToOne relationship. Let’s say a model User and a model Player. Each user is a player and each playeris a user.

Here is the code of these 2 models :

@Entity
public class User extends Model {

    @Required
    public String name;

    @OneToOne(fetch = FetchType.EAGER)
    public Player player;
}

@Entity
public class Player extends Model {

    @Required
    public String nickname;

    @Required
    public Gender gender;
}

I will always access a Player from a User and I want that when I load a User, his Player is also loaded (that’s why I used fetch = FetchType.EAGER).

So I expect (for optimization purposes) that when I load a User, the query is a JOIN query that also loads the Player.
Something like :

select u, p from User u join u.player p where u.player_id = p.id

But when I look at the queries count and the queries debug output I can see that 2 queries are performed.
Something like:

select u from User u
select p from Player p where p.id = ?

But this is not optimized, how can I make JPA perform a join request to get my User and its Player ?

Tank you for your help!

EDIT : I’m using Play framework 1.2.5

  • 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-13T14:48:47+00:00Added an answer on June 13, 2026 at 2:48 pm

    In the User class, as you noticed in your comment that the player can be null

    public static void findByIdWithPlayer(Long id) {
        find("select distinct user from User user left join fetch user.player where user.id=?", id).first();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have a django model with a OneToOne / Unique ForeignKey relationship
I have a Client model with a OneToOne relationship to User, to extend the
So, say I have models like this: class Foo(Model): name = CharField(max_length=200) def latest_comment(self):
I have a multi model with different OneToOne relationships from various models to a
I have an extended UserProfile model in django: class UserProfile(models.Model): user = models.ForeignKey(User, unique=True)
Say I have models: class Animal(models.Model): type = models.CharField(max_length=255) class Dog(Animal): def make_sound(self): print
I have models for eg like this class Model(): time=models.DateTimeField() free=models.BooleanField(default=False) user=models.ForeignKey(User) //it is
I have models A,B,C,D, etc. I have my usual controllers/views/helpers for each of these
Let us say we have models as such: Trigger belongs_to :position Position has_many :trigger
I have models like this: class Vendor(models.Model): title = models.CharField() class Product(models.Model): ... vendor

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.