I'm trying to intercept method calls to EntityManager in order to make modifications to some entities before persisting them.
I've tried many ways to do that (see http://stackoverflow.com/questions/8213285/how-to-intercept-methods-of-entitymanager-with-seam-3) but I see that the real problem is that it's not easy to make a proxy behind the EntityManager bean created by org.jboss.seam.persistence.ManagedPersistenceContextExtension.
It seems that a way to do that has been thinked, but cannot be used today. In ManagedPersistenceContextExtension.beforeBeanDiscovery, a Set of SeamPersistenceProvider s is created BUT org.jboss.seam.persistence.HibernatePersistenceProvider is always put in front of all others, so we cannot create our own provider to extend the features of current ones as it is chosen in EE environment which use hibernate (JBoss 7 for instance).
I think the best way to do that would be to create a Producer bean and not an instanciable bean, as with CDI we could replace that Producer with an @Observes ProcessProducer and a setProducer() to extend it.
At the moment, we can only @Observes ProcessBean on the EntityManager bean created by Seam Persistence, and do nothing about it as the CDI spec doesn't enable us to ask the container to replace the observed bean with ProcessBean.