If you want to expose the EntityManager you can do this as follows:

// in your private module:
final Provider<EntityManager> entityManagerProvider =
binder().getProvider(EntityManager.class);
bind(EntityManager.class).annotatedWith(MyDataSourceOne.class).toProvider(entityManagerProvider);
expose(EntityManager.class).annotatedWith(MyDataSourceOne.class);

Now the EntityManager is available outsied the private module:

@Inject @MyDataSourceOne
EntityManager entityManager;


And here is the code to the session provider you asked for:

public class SessionProvider implements Provider<Session> {
    /** The entity manger to retrieve the session from. */
    @Inject
    private Provider<EntityManager> entityManagerProvider;

    /**
     * @return the Hibernate session, being the delegate of the entity
manager provided by the injected entity manager provider.
     */
    @Override
    public Session get() {
        final Session session = (Session)
entityManagerProvider.get().getDelegate();
        // configure session i.e. flush mode or filtering
        return session;
    }

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to