• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate and JPA entity with spring framework

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Previously i was using spring jdbc template for persistence. Recently I was trying to use hibernate 3.2 while JPA annotations which eliminates the need for hibernate mapping xml files - all these are manged with Spring framework. Now I encounter one strange problem. I have one worker thread which retrieves some requests periodically and service them accordingly. I wrapped my code inside try{}catch(Throwable e){} within an infinite loop but i noticed that worker thread some times disappears (loop breaks) and it does not enter the catch block! Naturally I was confused with this behaviour since i believe that any exception should enter catch block.

After some googling i found UncaughtExceptionHandler. Inside uncaughtException function i simply log the error and its was great NullPointerException. So i was assuming that while hibernate making some query and finding NULL in some column, it catches the exception and not allowing it to bubble up. But i am not getting why the thread crashed !! It is making me really confused. Can you please show me some light.

Thanks in advance.
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is hibernate accessing your database?
 
Ahsan Habib
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the entity pojo -

Dao goes below -

Here is the spring config xml -

Finally here is how worker uses dao -

Thats all. Hope it helps to figure out the big picture of the scenario.
Thank you very much for your time.
 
Eduardo Bueno
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see any point where you can get a NullPointerException in your code, except if Spring is not injecting your DAO properly. Consider using getDao() instead of the attribute directly for a better approach. The exception could also be caused in method processJobs, if you consider that null is being returned from the database.
 
Ahsan Habib
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with you that I should examine method processJobs carefully. But what is not clear to me what why processJobs is not throwing NullPointerException which should be caught at the top level? The exception only caught by UncaughtExcptionHandler. What should be preferred coding convention to address such situation then - try/catch or UncaughtExcptionHandler?
 
Ahsan Habib
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Holy cow! I pointed out the problem. It is in the worker's infinite loop inside catch block (line number 18 of last code fragment)-

I believe even a dumb guy can imagine what happens when e.getCause() is null which I failed to locate so far. The catch bock was throwing some exception and thts why the loop breaks.

Thanks Bueno for your help so far.
 
reply
    Bookmark Topic Watch Topic
  • New Topic