<p>Suppose you have the following EJB 3 interfaces/classes:</p>

<pre><code>public interface Repository&lt;E&gt;
{
   public void delete(E entity);
}

public abstract class AbstractRepository&lt;E&gt;  implements Repository&lt;E&gt;
{
   public void delete(E entity){
      //...
   }
}

public interface FooRepository&lt;Foo&gt;
{
   //other methods
}

@Local(FooRepository.class)
@Stateless
public class FooRepositoryImpl extends
    AbstractRepository&lt;Foo&gt; implements FooRepository
{
   @Override
   public void delete(Foo entity){
      //do something before deleting the entity
      super.delete(entity);
   }
   //other methods
}
</code></pre>

<p>And then another bean that accesses the <code>FooRepository</code> bean :</p>

<pre><code>//...
@EJB
private FooRepository fooRepository;

public void someMethod(Foo foo)
{
    fooRepository.delete(foo);
}
//...
</code></pre>

<p>However, the overriding method is never executed when the delete method of the <code>FooRepository</code> bean is called. Instead, only the implementation of the delete method that is defined in <code>AbstractRepository</code> is executed. </p>

<p>What am I doing wrong or is it simply a limitation of Java/EJB 3 that generics and inheritance don't play well together yet ?</p>

[{'answer_id': 14920, 'author': 'Mike Deck', 'author_id': 1247, 'author_profile': 'https://Stackoverflow.com/users/1247', 'pm_score': 1, 'selected': False, 'text': "<p>Can you write a unit test against your FooRepository class just using it as a POJO.  If that works as expected then I'm not familiar with any reason why it would function differently inside a container.</p>\n\n<p>I suspect there is something else going on and it will probably be easier to debug if you test it as a POJO.</p>\n"}, {'answer_id': 15279, 'author': 'ScArcher2', 'author_id': 1310, 'author_profile': 'https://Stackoverflow.com/users/1310', 'pm_score': 3, 'selected': True, 'text': '<p>I tried it with a pojo and it seems to work. I had to modify your code a bit.\nI think your interfaces were a bit off, but I\'m not sure.</p>\n\n<p>I assumed "Foo" was a concrete type, but if not I can do some more testing for you.</p>\n\n<p>I just wrote a main method to test this.\nI hope this helps!</p>\n\n<pre><code>public static void main(String[] args){\n        FooRepository fooRepository = new FooRepositoryImpl();\n        fooRepository.delete(new Foo("Bar"));\n}\n\npublic class Foo\n{\n    private String value;\n\n    public Foo(String inValue){\n        super();\n        value = inValue;\n    }\n    public String toString(){\n        return value;\n    }\n}\n\npublic interface Repository&lt;E&gt;\n{\n    public void delete(E entity);\n}\n\npublic interface FooRepository extends Repository&lt;Foo&gt;\n{\n    //other methods\n}\n\npublic class AbstractRespository&lt;E&gt; implements Repository&lt;E&gt;\n{\n    public void delete(E entity){\n        System.out.println("Delete-" + entity.toString());\n    }\n}\n\npublic class FooRepositoryImpl extends AbstractRespository&lt;Foo&gt; implements FooRepository\n{\n     @Override\n       public void delete(Foo entity){\n          //do something before deleting the entity\n            System.out.println("something before");\n          super.delete(entity);\n       }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/14801', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1793/']