How to make Hibernate ignore a method?

前端 未结 3 1600
再見小時候
再見小時候 2021-01-03 22:09

This question is essentially the opposite of this one.

I have a method like so:

public boolean isVacant() {
    return getEmployeeNum() != null &         


        
3条回答
  •  Happy的楠姐
    2021-01-03 22:58

    RNJ is correct, but I might add why this happens:

    I'm guessing that you have annotated the getters of your persistent class. The prefixes used by java beans are "set" and "get", which are used do read and write to variables, but there is also the prefix "is", which is used for boolean values (instead of "get"). When Hibernate sees your getter-annotated persistent class, and finds a method "isVacant", it assumes that there is a property "vacant", and assumes that there is a "set"-method as well.

    So, to fix it, you could either add the @Transient annotation, or you could change the name of your method to something that doesn't start with "is". I don't think this would be a problem if your class was annotated on the fields, instead of the get-methods.

提交回复
热议问题