Hibernate ignore column mapping annotation - Java @ Desk

Saturday, November 1, 2014

Hibernate ignore column mapping annotation

Hibernate ignore column mapping annotation

In hibernate pojo, annotations are used for each property or their corresponding getter. We may require to add some property or method which we may want hibernate to ignore at runtime.

Say, for example there are four fields in Person Hibernate Pojo :
1) name
2) age
3) dateOfBirth
4) address

Consider a method isAbove18() is there which checks if date of birth is greater than 18 years from current date in a POJO.

public boolean isAbove18() {
 ...
}


Hibernate will complain, "above18" property is not available.

To resolve this, one can use "@Transient" annotation of JPA to inform Hibernate to ignore this property/method at runtime.

@Transient
public boolean isAbove18() {
 ...
}

@Transient
private String address;








No comments:

Post a Comment