• 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

use an entity bean in the contextInitialized method

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, can I use an entity bean in the ServletContextListener's contextInitialized method, to read some variables from the database?
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup, you can.

From within that method, the entire J2EE/JEE5 library is available to you. It's more the Servlet API that places restrictions on what can and cannot be seen. But yeah, you can write all the db access code you want in there! Be careful though, that's a nasty place to see a JDBC or Hibernate error. Nothing sucks more than your application failing to even initialize the context.

-Cameron McKenzie
 
Talabér Ferenc
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because I tried it, but sometimes I got the following error:

java.lang.IllegalArgumentException: Unknown entity bean class: class ... , please verify that this class has been marked with the @Entity annotation.

and sometimes it starts, and works well..


 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sometimes?

Do you have more than one instance on your classpath? That's a weird error to get inconsistently.
 
Talabér Ferenc
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At every 5-6. application start (in netbeans.. after this error I have to restart netbeans and it works again...)
I have only one instance.

Cameron Wallace McKenzie wrote:Sometimes?

Do you have more than one instance on your classpath? That's a weird error to get inconsistently.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic