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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:26:31+00:00 2026-05-25T22:26:31+00:00

I have hibernate pojo class A { B b ; some other properies} with

  • 0

I have hibernate pojo class A { B b ; some other properies} with lazy= true for class B.
When i get object A, B is not loaded and hibernate returns its proxy. When i pass this object to another module, that module traverse each and every objects in A and when it encounter B.getXXX it throws LazyInitialization exception. In this particular case, I do not want to load class B as it is not required. Is there any way when i call methods on B it either return null or turn proxy of B into real object B so that module doesn’t throw LazyInitialization error. I cannot change class B getter,setter as it common class and use by many other classes.

  • 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-25T22:26:32+00:00Added an answer on May 25, 2026 at 10:26 pm

    Thanks for all your suggestion.
    My application have layered architecture. Service->Manager->Dao. Hibernate session closes after manager. Other module interacts only through Service. Opening hibernate session till request complete is not an option for me. I also do not want to hit database as it is not necessary that properties of B are populated. I just want to replace hibernate proxy with real object so that anyone who is using service do not face any problem. I found a utility at
    http://svn.rhq-project.org/repos/rhq/branches/HEIKO-EXP/modules/enterprise/server/safe-invoker/src/main/java/org/rhq/enterprise/server/util/HibernateDetachUtility.java
    which exactly does what i want. It inspect object and replace hibernate proxy with real object. I need to customize following things in above utility
    1. Change instances of classname from org.rhq to my package structure.
    2. They expect name of identity field in pojo is “id”. I change it to use those property which has annotation of javax.persistence.Id.

    Basic testing with above changes is done and it is working fine. I just need to test whole application with various scenario so that it is working in all scenario.

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

Sidebar

Related Questions

I have a hibernate pojo class and it has some field. Assume that there
Let's say I have following POJO's using Hibernate. public class User { private String
I have a hibernate managed POJO with a set: public class Book { private
So we use Hibernate for Object-relational mapping and we have a Student.java (POJO) and
I have a Hibernate POJO with 1.an one-to-one association to another object 2.one-to-many association(collection)
We have hibernate-based system and customer wants to get human-readable names of PK and
We have an object, A, which contains another object, B. We have Hibernate calling
I have a Hibernate mapping that looks something like this: <class name=MyEntity> <set name=scalarSet
I have a hibernate object that gets detached and transferred to a thick java
I have a simple POJO mapped to a table using Hibernate. Which works just

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.