Categories
discuss

How can I override an EJB 3 session bean method with a generic argument – if possible at all? [closed]

Suppose you have the following EJB 3 interfaces/classes:

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
}

And then another bean that accesses the FooRepository bean :

//...
@EJB
private FooRepository fooRepository;

public void someMethod(Foo foo)
{
    fooRepository.delete(foo);
}
//...

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

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 ?

Answer

I tried it with a pojo and it seems to work. I had to modify your code a bit. I think your interfaces were a bit off, but I’m not sure.

I assumed “Foo” was a concrete type, but if not I can do some more testing for you.

I just wrote a main method to test this. I hope this helps!

public static void main(String[] args){
        FooRepository fooRepository = new FooRepositoryImpl();
        fooRepository.delete(new Foo("Bar"));
}

public class Foo
{
    private String value;

    public Foo(String inValue){
        super();
        value = inValue;
    }
    public String toString(){
        return value;
    }
}

public interface Repository<E>
{
    public void delete(E entity);
}

public interface FooRepository extends Repository<Foo>
{
    //other methods
}

public class AbstractRespository<E> implements Repository<E>
{
    public void delete(E entity){
        System.out.println("Delete-" + entity.toString());
    }
}

public class FooRepositoryImpl extends AbstractRespository<Foo> implements FooRepository
{
     @Override
       public void delete(Foo entity){
          //do something before deleting the entity
            System.out.println("something before");
          super.delete(entity);
       }
}
Categories
discuss

When should a multi-module project to split into separate repository trees?

Currently we have a project with a standard subversion repository layout of:

./trunk
./branches
./tags

However, as we’re moving down the road of OSGi and a modular project, we’ve ended up with:

./trunk/bundle/main
./trunk/bundle/modulea
./trunk/bundle/moduleb
./tags/bundle/main-1.0.0
./tags/bundle/main-1.0.1
./tags/bundle/modulea-1.0.0

The ‘build’ is still quite monolithic in that it builds all modules in sequence, though I’m starting to wonder if we should refactor the build/repository to something more like:

./bundle/main/trunk
./bundle/main/tags/main-1.0.0
./bundle/main/tags/main-1.0.1
./bundle/modulea/trunk
./bundle/modulea/tags/modulea-1.0.0

In this pattern I would imagine each module building itself, and storing its binary in a repository (maven, ivy, or another path of the subversion repository itself).

Are there guidelines or ‘best-practices’ over project layouts once one goes modular?

Answer

The Subversion book contains two sections on this:

A blog entry on the subject: “Subversion Repository Layout”

The short answer, though: while your mileage will vary (every situation is individual), your /bundle/<project>/(trunk|tags|branches) scheme is rather common and will likely work well for you.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..