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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:04:41+00:00 2026-06-06T17:04:41+00:00

I created a simple hello-wordish code using hibernate sf = new Configuration().configure().buildSessionFactory(); System.out.println(sessionFactory is

  • 0

I created a simple hello-wordish code using hibernate

sf = new Configuration().configure().buildSessionFactory();
System.out.println("sessionFactory is built.Get session object");
s = sf.openSession();
Kk emp = (Kk) s.get(Kk.class, 1);
if (null != emp) {
    System.out.println(emp.getId() + " " + emp.getNm());
} else {
   System.out.println("Emp doesn't exist..");
}

This code works fine and gives me 1 record, as seen below on console :-

sessionFactory is built.Get session object
Hibernate: select kk0_.id as id0_0_, kk0_.name as name0_0_ from kaushik1 kk0_ where kk0_.id=?
1 kaushik

But when I introduce a Load event listener class through hibernate configuration, the record is not fetched. Rather query itself is not fired.

My Listener class is :-

import org.hibernate.HibernateException;
import org.hibernate.event.LoadEvent;
import org.hibernate.event.LoadEventListener;

public class MyLoadListener implements LoadEventListener {

    public void onLoad(LoadEvent arg0, LoadType arg1) throws HibernateException {
        System.out.println("inside my own onLoad listener");
    }

}

And in my hibernate.cfg.xml I added line :-

<listener type="load" class="com.cts.eventlistener.MyLoadListener"/>

Now when same code is invoked, I can see on console :-

sessionFactory is built.Get session object
inside my own onLoad listener
Emp doesn't exist..

Why is query not getting invoked when onLoad of event listener is called ?

  • 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-06T17:04:43+00:00Added an answer on June 6, 2026 at 5:04 pm

    The need to configure DefaultLoadEventListener is bit counter intiutive.

    I found a better way in this case for that listener. Instead of implementing LoadEventListener interface we should “extend” DefaultLoadEventListener.
    We will override its onLoad() and inside it call super.onLoad(). This worked very well.

    import org.hibernate.event.LoadEvent;
    import org.hibernate.event.LoadEventListener;
    import org.hibernate.event.PreLoadEventListener;
    import org.hibernate.event.def.DefaultLoadEventListener;
    
    import com.cts.closr.Kk;
    
    public class MyLoadListener extends DefaultLoadEventListener  {
    
        public void onLoad(LoadEvent arg0, LoadType arg1) throws HibernateException {
            System.out.println("inside my own onLoad listener");
            super.onLoad(arg0, arg1);
        }
    
    }
    

    And in configuration only configure custom listener.

    <event type="load">
           <listener class="com.cts.eventlistener.MyLoadListener"/>
    </event>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a simple hello world application in xcode using the command line
I have created a simple Hello World Application using Flash Builder Burrito SDK. I
I'm trying out Visual Studio at the time. I created a simple hello world
I've created a simple webapp using Spring & Jetty, and am creating a hello
I created a simple asm hello world x86 bootloader, I'd like to embed it
Hello I`ve created simple WFC DataService and connected entit model with my database. This
Hello Stackoverflowers! I created a simple sqlite DB like so. //event table name private
I'm following this tutorial to create a simple Hello World extension for Chrome: http://code.google.com/chrome/extensions/getstarted.html
Could someone help me on this, I have created simple web services using axis2
I am new to Repository concept and get some questions. I have created simple

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.