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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:04:21+00:00 2026-06-18T07:04:21+00:00

I have a entity class class B{ @ManyToOne(fetch = FetchType.EAGER) private A a; @ManyToOne(fetch

  • 0

I have a entity class

class B{
    @ManyToOne(fetch = FetchType.EAGER)
    private A a;
    @ManyToOne(fetch = FetchType.LAZY)
    private C c;

}

In certain scenarios, I don’t want to load object A, since I already have that object.
and same for C also. But these are specific scenarios I don’t want to load those objects at all.

is there any way we can tell hibernate not to load certain properties of entity object. {no Eager/Fetch suggestions. I just want this to happen only in specific cases]

Note: I am using Criteria to fetch the object right now.

  • 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-18T07:04:22+00:00Added an answer on June 18, 2026 at 7:04 am

    Since you’re using HQL for your queries, you can specify your fetching strategy at runtime based on your condition using the “fetch” keyword, like below:

    List result = sess.createCriteria(B.class)
        .add( Restrictions.like("name", "yourcondition%") )
        .setFetchMode("a", FetchMode.EAGER)
        .setFetchMode("c", FetchMode.LAZY)
        .list();
    

    Edit:

    Since FetchMode.EAGER and FetchMode.LAZY is deprecated use, FetchMode.SELECT or FetchMode.JOIN

    List result = sess.createCriteria(B.class)
        .add( Restrictions.like("name", "yourcondition%") )
        .setFetchMode("a", FetchMode.JOIN)
        .setFetchMode("c", FetchMode.SELECT)
        .list();
    

    If you want to avoid the SELECT or JOIN check here.

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

Sidebar

Related Questions

I have an Entity like this: public class Configuration { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name
I have this simple situation: @Entity public class Customer{ @ManyToMany(fetch=FetchType.EAGER) @Cascade(CascadeType.SAVE_UPDATE) private List<Product> products=new
I have these 2 classes: @Entity public abstract class Compound { @OneToMany(fetch = FetchType.EAGER,
I have the following two entities: @Entity class Relation{ @ManyToOne private User user; //some
I have an entity class Document and another one called Space. The relation: @ManyToOne(fetch
I have a class according to: @Entity public class Car { @Id @GeneratedValue private
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
In my business model I have Entity class (IPoint interface ) that has a
I used JPA and mysql. Each table have entity class.I have four tables. Table1
I have an entity class Foo foo that contains Collection<Bar> bars . I've tried

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.