在我的 POJO 中,我有这个:
@Transient
private int qtyMentee;
在我的 DAO 中我有这个查询:
public List<Employee> findQtyMentee(){
TypedQuery<Employee> query = (TypedQuery<Employee>) em.createNativeQuery(
"select *, count(mentor_id) as qtymentee from employee group by id order by qtymentee asc" , Employee.class);
Collection<Employee> employee = (Collection<Employee>) query.getResultList();
return (List<Employee>) employee;
}
当我尝试让 Qtymentee 返回 0 时。
在这种情况下注释@Transient
是错误的?
如何获取该值并在我的应用程序中显示?
OBS:我正在使用 Eclipselink。
谢谢。
最佳答案
标有@Transient的字段将不会被持久化。这意味着它们的值不存在于数据库中,并且在查询中使用它们将不会产生任何效果。从规范来看:
This annotation specifies that the property or field is not persistent.
关于java - 坚持@Transient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29490779/