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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:17:33+00:00 2026-06-11T04:17:33+00:00

When I load an entity which contains lazy-loading fields and I want to send

  • 0

When I load an entity which contains lazy-loading fields and I want to send this entity through an object message with ActiveMQ, will I receive :

  1. The full entity (with lazy-loading fields loaded)
    OR
  2. The entity as sent (without lazy-loading fields loaded) ?

In any case do I need to put the Serializable marker in my entity ?

In case of answer 1 what do I need to do to get the entity as described in answer 2 ?

  • 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-11T04:17:35+00:00Added an answer on June 11, 2026 at 4:17 am

    Lets assume you have an entity with some lazy loading fields like this:

    @Entity
    public class Foo
    {
        @Id
        private Long id;
        @OneToMany
        private List<Bar> bars;
    }
    

    When you receive this entity from your database only the id field will be loaded as the bars field is lazy loaded (OneToMany is lazy by default). Now when you pass this entity through JMS for example the bars field is not initialized because the getBars() method isn’t called. When the remote end calls the getter it will get a LazyInitializationException as the entity is detached and the collection isn’t initialized.

    If you however want the remote end to be able to call the getBars() method you need to initialize the collection in some way. You can make the fetching of the collection eager using @OneToMany(fetch = FetchType.EAGER). An alternative is to use a separate query for eager loading the entity (which is my personal preference).

    Example:

    select f from Foo f join fetch l.bars
    

    If you really want to go wild and want the collection to be initialized lazily on the remote end you can take a look at Hibernate remote lazy loading using RMI. I’m not going to explain this because it seems out of the scope of the question. 😉

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

Sidebar

Related Questions

I have this error message could not load assembly 'system.data.entity, version 4.2.0.0, culture=neutral,publickeytoken=b77a5c561934e089' or
consider this scenario: I have loaded a Parent entity through hibernate Parent contains a
I have 2 entity's AlienImage.cfc MonsterImage.cfc Both these entity's inherit from Image.cfc which contains
I have a object structure like this: public class Entity { IList<Relationship> Relationships{get;set;} }
I have one entity which besides other information holds many images. This is one
I'm writing a little utility to load Entity Data Models from an assembly and
I am trying to load an entity by key using the id it was
I have an entity loaded by Hibernate (via EntityManager ): User u = em.load(User.class,
load.js: jQuery(document).ready(function($) { $('.dialog ul li').click(function(e) { switch($(this).attr('id')) { case 'addProject': $('.addDialog').load('/add/addprojectform'); break; case
I load some images into an object list , and then try to recall

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.