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?
To ignore a field, annotate it with @Transient so it will not be mapped by hibernate.
@Transient annotation in JPA or Hibernate is used to indicate that a field is not to be persisted or ignore fields to save in the database. @Transient exist in javax. persistence package. It is used to annotate a property or field of an entity class, mapped superclass, or embeddable class.
When persisting Java objects into database records using an Object-Relational Mapping (ORM) framework, we often want to ignore certain fields. If the framework is compliant with the Java Persistence API (JPA), we can add the @Transient annotation to these fields.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With