views:

26

answers:

1

I have a few Hibernate Envers listeners which I use for audit purposes. I am just getting started on CDI and so far am pleasantly surprised by its simplicity and power. Since it seems everything is integrating CDI functionality, I thought I'd raise the question, is Hibernate supporting it or will it?

Not only would it be nice to have access to various components, but it would also be great to have access to other contextual information easily and not be limited by Hibernate's interfaces.

A: 

The question should be the other way around - will CDI support hibernate integration.

What CDI has to support, probably via an extension, is:

  • injecting an EntityManager where there is @PersistenceContext, and EntityManagerFactory where there is @PersistenceUnit
  • transaction and session lifecycle handling

Google for "Weld Persistence Context" and you'll get some examples of how to use Hibernate (JPA) with Weld, which is the reference implementation of CDI. Read this thread as well. And this example

Bozho
I guess perhaps that is the way it would have to work. I want easy access to contextual information that CDI provides. I want to inject components into my listeners to evaluate security or do other sophisticated things with very little effort.
To your point, I am working on a CDI extension that permits you to write queries with an interface. Similar to using @NamedQuery, you will write your actual query on the method. The method will allow you to specify the parameters for your query as well as return type giving you type safety whereas an Entity Query does not. I'd also like to see this hooked into @Producer / @WebRemote so that you can easily have a web service with 3 lines of code.