如何制作通用 EJB class

How to make a generic EJB class

我有两个名为:地址和客户端的实体。 我有一个看起来像这样的界面:

public interface IDAOEnitityFactory extends Serializable{
List<Address> findAllByClass();
}

实现看起来像:

 @Stateless
@Local(IDAOEnitityFactory.class)
 public class DAOEnitityFactory implements IDAOEnitityFactory {
@PersistenceContext(unitName = "MY_PU")
protected EntityManager entityManager;

@Override
public List<Address> findAllByClass() {     
    return this.getAuditReader().createQuery()
            .forRevisionsOfEntity(Address.class, true, false)
            .setMaxResults(10).getResultList();
}

所以我想做一个通用的实现,我只传递 Adress 或 Client 和 findAllByClass return。 我该怎么做?

我有一颗豆子:

@EJB
private IDAOEnitityFactory dao;
for(Address st:dao.findAllByClass()){
                System.out.println(st.getID);               
            }

我想我找到了解决方案:

public interface IDAOEnitityFactory extends Serializable{
T List<T> findAllByClass(Class c);
 }

@Stateless
@Local(IDAOEnitityFactory.class)
public class DAOEnitityFactory implements IDAOEnitityFactory {
@PersistenceContext(unitName = "MY_PU")
protected EntityManager entityManager;
@Override
public List<T> findAllByClass(Class c) {     
return this.getAuditReader().createQuery()
        .forRevisionsOfEntity(c, true, false)
        .setMaxResults(10).getResultList();
 }

@EJB
private IDAOEnitityFactory dao;
for(Object st:dao.findAllByClass(Address.class)){
            System.out.println((Address)st)st.getID);               
        }

也许还有其他的解决办法。母鸡?