• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

How to inject EntityManager via Eclipselink?  RSS feed

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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

 
Creator of Enthuware JWS+ V6
Bartender
Posts: 3120
259
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In what kind of EE - component are you injecting the EntityManager ( EJB, Servlet, CDI bean )?
 
Stephan Wöbbeking
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It never occured to me that tomcat maybe could NOT be a valid JEE container, is it???

Stephan
 
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender
Posts: 3120
259
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tomcat only consists of a web-container (no ejb-container).
 
Stephan Wöbbeking
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I guess that's the point in it... Don't know why it never occured to me...
Thanks anyway, now I will keep on struggling with TomEE configuration, but that's a different story,
Stephan
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!