Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

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
Posts: 3217
283
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
Posts: 3217
283
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
 
He does not suffer fools gladly. But this tiny ad does:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!