Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does @AttributeOverride mean?

I'm currently coming (back) up to speed with EJB and while I was away it changed drastically (so far for the better). However, I've come across a concept that I am struggling with and would like to understand better as it seems to be used in our (where I work, not me and all the voices in my head) code quite a bit.

Here's the example I've found in a book. It's part of an example showing how to use the @EmbeddedId annotation:

@Entity public class Employee implements java.io.Serializable {     @EmbeddedId     @AttributeOverrides({         @AttributeOverride(name="lastName", column=@Column(name="LAST_NAME"),         @AttributeOverride(name="ssn", column=@Column(name="SSN"))     })      private EmbeddedEmployeePK pk;      ... } 

The EmbeddedEmployeePK class is a fairly straightforward @Embeddable class that defines a pair of @Columns: lastName and ssn.

Oh, and I lifted this example from O'Reilly's Enterprise JavaBeans 3.1 by Rubinger & Burke.

Thanks in advance for any help you can give me.

like image 288
jaydel Avatar asked Dec 13 '10 19:12

jaydel


People also ask

What is AttributeOverride?

The @AttributeOverride annotations allow you to override the columns to which the embedded class's properties are mapped. The use case for this is when the embeddable class is used in different situations where its column names differ, and some mechanism is required to let you change those column mappings.

What is the use of@ AttributeOverride?

Annotation Type AttributeOverride. Used to override the mapping of a Basic (whether explicit or default) property or field or Id property or field.

Can attributes be overridden in Java?

You can not override a attribute, only hide it.


2 Answers

It's saying that the attributes that make up the embedded id may have predefined (through explicit or implicit mappings) column names. By using the @AttributeOverride you're saying "ignore what other information you have with regard to what column it is stored in, and use the one I specify here".

like image 50
zmf Avatar answered Sep 27 '22 20:09

zmf


AttributeOverride

In the UserDetails class, I have overridden homeAddress & officeAddress with Address

This One Address POJO will act for two table in DB.

DB:

Table1      Table2 STREET_NAME HOME_STREET_NAME CITY_NAME   HOME_CITY_NAME STATE_NAME  HOME_STATE_NAME PIN_CODE    HOME_PIN_CODE 
like image 28
Ravi Parekh Avatar answered Sep 27 '22 19:09

Ravi Parekh