posted 6 months ago
Hi *,
I am currently struggling as I can't get all the details together. I do have a working database (Derby, coming with jdk1.8.0_141) and a running TomCat (apache-tomcat-8.5.23) on top. For the JPA I use EclipseLink (eclipselink-2.7.0.v20170811-d680af5). The general access to the database works fine, this is how I get the EntityManager:
This is my persistence.xml:
Now I tried to have the EntityManager being injected like this:
Of course I have modified the persistence.xml in various ways, but I couldn't get it to work. The EntityManager "em2" is always null!
Can anyone tell me, what I am missing here? Thanks a lot guys!
Stephan
Hi *,
I am currently struggling as I can't get all the details together. I do have a working database (Derby, coming with jdk1.8.0_141) and a running TomCat (apache-tomcat-8.5.23) on top. For the JPA I use EclipseLink (eclipselink-2.7.0.v20170811-d680af5). The general access to the database works fine, this is how I get the EntityManager:
This is my persistence.xml:
Now I tried to have the EntityManager being injected like this:
Of course I have modified the persistence.xml in various ways, but I couldn't get it to work. The EntityManager "em2" is always null!
Can anyone tell me, what I am missing here? Thanks a lot guys!
Stephan
Stephan Wöbbeking
Greenhorn
Posts: 27
posted 6 months ago
Good point! I was playing around with it a little bit. I tried @Stateful and @EJB. The class is marked as @ManagedBean, @SessionScoped, @Entity as well... The number of combinations between different annotations and choices for naming in the persistence.xml is to high, I just wasn't able to try it all. So I need less trial and error and more knowledge. ;))
Stephan
Frits Walraven wrote:In what kind of EE - component are you injecting the EntityManager ( EJB, Servlet, CDI bean )?
Good point! I was playing around with it a little bit. I tried @Stateful and @EJB. The class is marked as @ManagedBean, @SessionScoped, @Entity as well... The number of combinations between different annotations and choices for naming in the persistence.xml is to high, I just wasn't able to try it all. So I need less trial and error and more knowledge. ;))
Stephan
Stephan Wöbbeking
Greenhorn
Posts: 27
