2013-12-10 75 views

回答

1

我不認爲這是可以做到上面,但是Eclipse中生成以下類型的方法在其自動生成的DAO的

public List<Table> findByProperty(String propertyName, final Object value) { 
    EntityManagerHelper.log("finding TableName instance with property: " 
      + propertyName + ", value: " + value, Level.INFO, null); 
    try { 
     final String queryString = "select model from TableName model where model." 
       + propertyName + "= :propertyValue"; 
     Query query = getEntityManager().createQuery(queryString); 
     query.setParameter("propertyValue", value); 
     return query.getResultList(); 
    } catch (RuntimeException re) { 
     EntityManagerHelper.log("find by property name failed", 
       Level.SEVERE, re); 
     throw re; 
    } 
}