Hi Berthold!

I have a very similar structure with a 

public abstract class GenericService<T extends BaseEntity> {
    public T create(final T entity) {
        log.info("create new " + getEntityClass().getSimpleName() + " : " + 
entity);
        getEntityManager().persist(entity);
        return entity;
    }

    @Override
    public T getById(final Object primaryKey) {
        return getEntityManager().find(getEntityClass(), primaryKey);
    }
...
}

but I don't use interceptor declaration on methods but I've annotated my whole 
specialised Service as @Transactional.
Could you try this please?  

> it seems that a "wrong" method is being called - one with the signature 
> "void delete(java.lang.Object)" instead of "void delete(Customer)"
This may look like due to 'type erasures'. See [1][2] for more information.

LieGrue,
strub

[1] http://java.sun.com/docs/books/tutorial/java/generics/erasure.html
[2] 
http://www.angelikalanger.com/Articles/JavaMagazin/Generics/GenericsPart2.html

--- On Fri, 5/21/10, Berthold Scheuringer <[email protected]> 
wrote:

From: Berthold Scheuringer <[email protected]>
Subject: Method Interception Problem
To: [email protected]
Date: Friday, May 21, 2010, 9:19 AM

Hi all, 

I recently built a little app where I wanted to demonstrate method interception 
with CDI (OWB).
Therefore I created a (really simple) transaction interceptor. 
In the sample app there is a service layer with a basic and a special service 
interface (GenericService --> CustomerService).


The basic service interface uses generics (e.g. public interface 
GenericService<T> ). I put the @MyTransactional interceptor binding on the 
methods in the implementation class (e.g. CustomerServiceImpl).



Here it turned out that interception does not work on methods where I used the 
generic type as parameter (e.g.: void delete(T obj); ).Furthermore it does work 
if the method has no parameter or if I override the method in the special 
interface (e.g. if I define void delete(Customer customer) in the 


CustomerService interface) 
I created a little test app to retest this scenario 3 tests (svn link at 
[1])test a method with no parameter - will succeed
test a method with a parameter but overridden in the CustomerService interface 
- will succeed

test a method with a parameter and just defined in the GenericService interface 
- will fail I investigated a little bit on this problem - but I get stucked at 
the InterceptorHandler#invoke method - there


it seems that a "wrong" method is being called - one with the signature "void 
delete(java.lang.Object)" instead of "void delete(Customer)".It seems a little 
bit weird to me at all that there is a method with the java.lang.Object as 
parameter (in the runtime type) - since this is not defined 


anywhere (is this a compiler problem with generics and type erasure ?).
Would be great if anyone has an idea how to solve that issue (without using 
above mentioned workarounds).

 regards
Berthold



[1] svn 
repo: http://bs-owb-sandbox.googlecode.com/svn/trunk/owb-interceptors-test





Reply via email to