wood burning stoves 2.0*
The moose likes Java in General and the fly likes CDI question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "CDI question" Watch "CDI question" New topic
Author

CDI question

Tanya Ruttenberg
Ranch Hand

Joined: Jun 22, 2009
Posts: 40
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

Joined: Jan 28, 2003
Posts: 4168
    
  21

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.


Steve
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: CDI question
 
Similar Threads
Hibernate configuration issue: connection provider or hibernate.dialect issue
Comment on this hibernate util class
Hibernate:error "org.hibernate.HibernateException: /hibernate.cfg.xml not found"
session manager
org.hibernate.InvalidMappingException