[weld-issues] [JBoss JIRA] Updated: (WELD-356) @PersistenceContext not injected in target bean when bean is intercepted

William Draï (JIRA) jira-events at lists.jboss.org
Tue Dec 29 21:06:30 EST 2009


     [ https://jira.jboss.org/jira/browse/WELD-356?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

William Draï updated WELD-356:
------------------------------

    Description: 
Say you have this bean :

@MyInterceptorBinding
public class MyServiceBean implements MyService {

	@PersistenceContext
        protected EntityManager entityManager;
	
	@Inject @Any
	private Event<MyEvent> myEvent;

    
        public Object persist(Object obj) {
		entityManager.persist(obj);
		
		myEvent.fire(new MyEvent());
		
                return obj;
     }
}

Where @MyInterceptorBinding is a simple interceptor binding with a trivial interceptor implementation :

@MyInterceptorBinding @Interceptor
public class MyInterceptor {

	@AroundInvoke
	public Object doInvoke(InvocationContext context) {
		Object result = null;
		
    	try {
    		return context.proceed();
    	}
    	catch (Exception e) {
                throw new RuntimeException("error", e);
	}
}

The MyEvent field of the bean is correctly injected, but the entityManager is null. 
Note that if injecting @PersistenceContext EntityManager entityManager in the interceptor works fine.

When the bean is not intercepted, its entityManager field is correctly injected.


  was:
Say you have this bean :

@MyInterceptorBinding
public class MyServiceBean implements MyService {

	@PersistenceContext
        protected EntityManager entityManager;
	
	@Inject @Any
	private Event<MyEvent> myEvent;

    
        public Object persist(Object obj) {
		entityManager.persist(obj);
		
		myEvent.fire(new MyEvent());
		
                return obj;
     }
}

Where @MyInterceptorBinding is a simple interceptor binding with a trivial interceptor implementation :

@MyInterceptorBinding @Interceptor
public class MyInterceptor {

	@AroundInvoke
	public Object doInvoke(InvocationContext context) {
		Object result = null;
		
    	try {
    		return context.proceed();
    	}
    	catch (Exception e) {
                throw new RuntimeException("error", e);
	}
}

The MyEvent field of the bean is correctly injected with an MyEventImpl, but the entityManager is null.

When the bean is not interceptor, the entityManager field is correctly injected.




> @PersistenceContext not injected in target bean when bean is intercepted
> ------------------------------------------------------------------------
>
>                 Key: WELD-356
>                 URL: https://jira.jboss.org/jira/browse/WELD-356
>             Project: Weld
>          Issue Type: Bug
>          Components: Interceptors and Decorators
>    Affects Versions: 1.0.0.GA
>         Environment: JBoss 6.0.0.M1 and GlassFish V3 final
>            Reporter: William Draï
>
> Say you have this bean :
> @MyInterceptorBinding
> public class MyServiceBean implements MyService {
> 	@PersistenceContext
>         protected EntityManager entityManager;
> 	
> 	@Inject @Any
> 	private Event<MyEvent> myEvent;
>     
>         public Object persist(Object obj) {
> 		entityManager.persist(obj);
> 		
> 		myEvent.fire(new MyEvent());
> 		
>                 return obj;
>      }
> }
> Where @MyInterceptorBinding is a simple interceptor binding with a trivial interceptor implementation :
> @MyInterceptorBinding @Interceptor
> public class MyInterceptor {
> 	@AroundInvoke
> 	public Object doInvoke(InvocationContext context) {
> 		Object result = null;
> 		
>     	try {
>     		return context.proceed();
>     	}
>     	catch (Exception e) {
>                 throw new RuntimeException("error", e);
> 	}
> }
> The MyEvent field of the bean is correctly injected, but the entityManager is null. 
> Note that if injecting @PersistenceContext EntityManager entityManager in the interceptor works fine.
> When the bean is not intercepted, its entityManager field is correctly injected.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the weld-issues mailing list