Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CDI question

 
Tanya Ruttenberg
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a simple java program. There are 10 classes, 4 of which are @Entity beans using hibernate 4 to interface with the database. It runs the old-fashioned way from the command line, eg "java -jar myapp.jar". When I implemented hibernate in this app I followed some rather old examples that include a HibernateUtil.java class.



Hibernate sessions are grabbed via



boilerplate stuff, as far as I can tell.

It works fine the way it is, but I decided to re-design the thing using CDI. I'm wondering if there is some nifty, new way to grab those hibernate sessions, maybe using CDI? But this is not an J2EE app, there is nothing enterprise-y about it. When I try to inject a persistence context or entity manager it comes up "null". And I can't find a single discussion or example of doing this that is not a J2EE app.

Is it possible to acquire a hibernate session using CDI or some other nifty annotation in a plain old java program? Or is this only possible in a J2EE context?

Am I misunderstanding something fundamental? (would not be the first time!)

TDR
 
Steve Luke
Bartender
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Introduction to Contexts and Dependency Injection
Chapter 28
Introduction to Contexts and Dependency Injection for the Java EE Platform
Contexts and Dependency Injection (CDI) for the Java EE platform is one of several Java EE 6 features that help to knit together the web tier and the transactional tier of the Java EE platform.

Looks like CDI is a Java EE feature - you need to be using Java EE 6 to use it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic