这个问题本质上与this one相反.
我有这样一个方法:
public boolean isVacant() {
return getEmployeeNum() != null && getEmployeeNum().equals("00000000");
}
当我加载它时,Hibernate 提示我没有名为 vacant
的属性。但我不想要一个名为 vacant
的属性 - 我不需要存储该数据 - 这只是逻辑。
hibernate 说:
org.hibernate.PropertyNotFoundException: Could not find a setter for property vacant in class com.mycomp.myclass...
是否有注释可以添加到我的 isVacant()
方法中以使 Hibernate 忽略它?
最佳答案
将 @Transient
添加到方法中,然后 Hibernate 应该忽略它。
Every non static non transient property (field or method depending on the access type) of an entity is considered persistent, unless you annotate it as
@Transient
.
关于java - 如何让 Hibernate 忽略一个方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12359346/