I'm using JPA with Guice Persist for my GAE projects and Restlet for the REST interface. Under the hood good old Hibernate delivers the JPA service.
This works like a charm, and Guice injects necessary JPA parts into my classes, for example an EntityManager
in the RestletServlet
;
Now i want to use a SessionInterceptor
to insert create/edit timestamps and current active users to my entities. In old projects i used a static HibernateUtil
class with ThreadLocal variables to store the sessions. In my new project i want to solve this with Guice. Guice needs to inject an EntityManager
in my SessionInterceptor
so i can load the current active user from the database.
The SessionInterceptor
needs to be created in a Hibernate context and its not permitted to configure this after startup. Therefore i created a SessionInterceptorFactory
which uses a Guice Injector. In persistence.xml
This works (yes its ugly), i have a SessionInterceptor
with Guice Injection.
But when i try this code;
[ERROR] 1) No implementation for javax.persistence.EntityManager was bound. [ERROR] while locating com.google.inject.Provider [ERROR]
for the 1st parameter of com.ludus.server.hibernate.SessionInterceptor.(SessionInterceptor.java:20) [ERROR] while locating com.ludus.server.hibernate.SessionInterceptor
I need to connect (bound
) the JPA (Hibernate) configuration with the SessionInterceptor
in Guice like i did with the RestletServlet
, but how?
Who can help me with this Guice configuration?
Apart from this, the current SessionInterceptorFactory
is a 'dirty Guice hack', is there a clean Guice solution for this?