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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:18:38+00:00 2026-05-23T17:18:38+00:00

I have the following @OneToOne relation: @Entity @Table(name=USER) public class User implements Serializable{ private

  • 0

I have the following @OneToOne relation:

@Entity
@Table(name="USER")
public class User implements Serializable{

private Basket basket;

    @OneToOne(cascade = CascadeType.ALL,orphanRemoval=true,mappedBy="user", fetch=FetchType.LAZY )
    public Basket getBasket() {
        return basket;
    }

    public void setBasket(Basket basket) {
        this.basket = basket;
    }

//all other proerties are ommited and none relevant. 
}

Now the basket class:

@Entity
@Table(name="BASKET")
public class Basket implements Serializable {

private User user;

@OneToOne(fetch=FetchType.LAZY)
    public User getUser() {
        return user;
    }
//all other proerties are ommited and none relevant. 
}

Now I’m trying to fetch User object using HQL in object which has Spring Transaction manager using AOP:

public User getUser(String param1,String param2) {
    Session session = this.sessionfactory.getCurrentSession();
    String queryString = "from objects.User user where user.param1=:param1 and user.param2=:param2";
    Query query = session.createQuery(queryString); 
    query.setString("param1", param1);
    query.setString("param2", param2);
    User user = (User) query.uniqueResult();
    return user;
}

but I see that Basket is also fetched although it’s Lazy:

Hibernate: select user0......
Hibernate: select basket0.....

Why?

  • 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-23T17:18:39+00:00Added an answer on May 23, 2026 at 5:18 pm

    Because a one-to-one normally represents highly cohesive objects and is fetched using a join by default, so there’s little reason not to fetch both user and basket. I’m not sure why you’re seeing two separate selects. I believe that should only happen if you tell it specifically to fetch using a select instead of a join. This article does a good job of analyzing a one-to-one relationship. It might help you out.

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

Sidebar

Related Questions

I have the following (simplified) Hibernate entities: @Entity @Table(name = package) public class Package
I have following class ( entity ) @Entity public class Magazine { private int
I have the following situation: @Entity class A{ @Id @SequenceGenerator(name = SEQ_AID, sequenceName =
HI, I have the following model: @Entity class Flight{ private Airport airportFrom; private Airport
@Entity public class Organization { @OneToOne(fetch = FetchType.EAGER) @OnDelete(action = OnDeleteAction.CASCADE) @Cascade(value = DELETE_ORPHAN)
i have the following classes: //Product class public class Product { @Id @GeneratedValue private
I have following mapping definitions: <class name=Role table=Role optimistic-lock=version > <id name=Id type=Int32 unsaved-value=0
I have following situation: I have loged user, standard authentication with DB table $authAdapter
I have following classes. class A { public: void fun(); } class B: public
I have following wrapper to help me manage the wcf client lifetime: public class

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.