假设您有以下 EJB 3 接口/类:
public interface Repository<E>
{
public void delete(E entity);
}
public abstract class AbstractRepository<E> implements Repository<E>
{
public void delete(E entity){
//...
}
}
public interface FooRepository<Foo>
{
//other methods
}
@Local(FooRepository.class)
@Stateless
public class FooRepositoryImpl extends
AbstractRepository<Foo> implements FooRepository
{
@Override
public void delete(Foo entity){
//do something before deleting the entity
super.delete(entity);
}
//other methods
}
然后是另一个访问 bean 的FooRepository
bean:
//...
@EJB
private FooRepository fooRepository;
public void someMethod(Foo foo)
{
fooRepository.delete(foo);
}
//...
FooRepository
但是,当调用 bean的 delete 方法时,不会执行覆盖方法。相反,仅执行中定义的删除方法的实现AbstractRepository
。
我做错了什么,或者仅仅是 Java/EJB 3 的限制,泛型和继承还不能很好地结合在一起?