Using Java generics for JPA findAll() query with WHERE clause

前端 未结 4 1269
庸人自扰
庸人自扰 2020-12-14 02:50

So, After a 10+ year break I\'m coming back to Java and trying out stuff with JPA and Java generics. I\'ve created a generics based findAll(other) JPA query tha

4条回答
  •  借酒劲吻你
    2020-12-14 03:38

    This will work, and if you need where statement you can add it as parameter.

    class GenericDAOWithJPA {
    

    .......

    public List findAll() {
                return entityManager.createQuery("Select t from " + persistentClass.getSimpleName() + " t").getResultList();
        }
    }
    

提交回复
热议问题