hibernate - Injection in custom ConnectionProvider with CDI and Hibernate4 -


in java ee 7 project need custom connectionprovider, call db-function logged userid, , set db-session variables.

my problem, can't inject logged user in myconnectionprovider, in other beans - without problem.

this connectionprovider:

@sessionscoped @named public class myconnectionprovider implements connectionprovider, configurable, serializable {  @inject private logger log;  @inject @loggedin private user currentuser = null; 

here class login currentuser initialized:

@sessionscoped @named public class login implements serializable {  @inject private credentials credentials;  @persistencecontext private entitymanager userdatabase;  private user currentuser;  //.....................................  @produces @loggedin @named @sessionscoped public user getcurrentuser() {   return currentuser; } 

and interface loggedin:

@retention(retentionpolicy.runtime) @target({type, parameter,  method, field}) @qualifier public @interface loggedin {} 

may has same problems ?

hibernate not provide injection support these classes. instantiated directly, , singleton within persistence unit.

you can still kind of functionality, use cdi utility class references. cdi.current().select(user.class, new loggedinliteral()).get() user.class class of type you're expecting, , loggedinliteral qualifier instance.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -