@AttributeOverrides and @AttributeOverride Annotations

@AttributeOverrides and @AttributeOverride Annotations
In our previous example we had seen how to inject one entity into another entity(here). We have injected the address class into employee class. In that example we have not renamed the fields in the address class (city, state and pincode). We accepted the default field names – city, state and pincode.

In this example we are going to see, how we are going to change the name of the fields for the members in address class. There are 2 ways of doing it,

Method 1:
This method is similar to previous example. Just like we used @Column annotation in employee class, we can use the same annotation in address class and rename the database column name.

Method 2:
We can change the name of the column for the members in address class using @AttributeOverrides and @AttributeOverride annotations.

Method 1 has already been explained in previous example, Lets see the example for Method 2 in this article.






In employee.java, We have used @AttributeOverrides – This annotation is used when we have to change the column names for more than one member and @AttributeOverride is the annotation used to change the column name for each variable



We can see that the column names has been changed to City_Override, Pincode_Override and Street_Override





Leave a Reply

Your email address will not be published. Required fields are marked *