Less than 42 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to inject EntityManager into singleton at startup?  RSS feed

 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I want to query database when application starts. I want to do such queries only once !
For this I use singleton with @Startup annotation.

Unfortunately all ways to obtain EntityManager fails. I always have EntityManager is null.
If I inject session bean into my singleton it is null too.

How to inject EntityManager into singleton at startup?
How to perform quries on database only once per application at singleton startup?

Thank you!
 
Bin Smith
Ranch Hand
Posts: 514
1
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have solved it already.

The problem was that in singleton's constructor entitymanager was really null.
BUT in @PostConstruct lifecycle method my entitymanager was not null !!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!