Hi Mark, Thanks for your fast reply - putting the interceptor binding on class level does work.
However, as I just want to get only some of the methods intercepted - this is not 100% suitable for my case (of course I can work around this with changing design - but it would be nice to have it working also on method level) >> 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. Yes, I also think that type erasure is somehow involved here - but its interesting that in the above example 2 delete methods are defined at runtime - one with java.lang.Object as parameter and one with Customer class as parameter - and this is only the case for methods which have a generic parameter (e.g. its not the case for the "findAll()" method). It would be nice if you could test the method level interception also on your system to see if the problem occurs there also. regards, Berthold On Fri, May 21, 2010 at 11:48 AM, Mark Struberg <[email protected]> wrote: > 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 > > > > > > -- Berthold Scheuringer +43 664 80508 3919 Irian Solutions GmbH Your JSF powerhouse http://www.irian.at
