本文介绍了如何让Hibernate忽略一个方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 这个问题本质上与相反这一个。 我有一个像这样的方法: public boolean isVacant(){ return getEmployeeNum()!= null&& 。getEmployeeNum()等于( 00000000); } 当我加载它时,Hibernate抱怨我没有属性叫做空置。但我不想要一个名为 vacant 的属性 - 我不需要存储这些数据 - 它只是逻辑。 org.hibernate.PropertyNotFoundException:无法在类com.mycomp.myclass中找到属性为空的setter。 。 是否有可以添加到 isVacant()方法的注释让Hibernate忽略它?解决方案 在方法中添加 @Transient 那么Hibernate应该忽略它。 引用 Hibernate文档: 每个非静态非除非您将它标注为 @Transient 。 ,但实体的暂时属性(取决于访问类型的字段或方法) blockquote> This question is essentially the opposite of this one.I have a method like so:public boolean isVacant() { return getEmployeeNum() != null && getEmployeeNum().equals("00000000");}When I load it up, Hibernate is complaining that I have no attribute called vacant. But I don't want an attribute called vacant - I have no need to store that data - it's simply logic.Hibernate says: org.hibernate.PropertyNotFoundException: Could not find a setter for property vacant in class com.mycomp.myclass...Is there an annotation I can add to my isVacant() method to make Hibernate ignore it? 解决方案 Add @Transient to the method then Hibernate should ignore it.To quote the Hibernate Documentation: 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. 这篇关于如何让Hibernate忽略一个方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-21 03:23