• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

CDI question

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic