Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use an entity bean in the contextInitialized method

 
Talabér Ferenc
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic