3
@Entity
class User {
@EmbeddedId
@AttributeOverride(name="firstName", column=@Column(name="fld_firstname")
UserId id;
Integer age;
}
@Embeddable
class UserId implements Serializable {
String firstName;
String lastName;
}

I want to know what is the use of AttributeOverride. This is the code from hibernate online docs

skaffman
  • 398,947
  • 96
  • 818
  • 769
  • 3
    possible duplicate of [What does @AttributeOverride mean?](http://stackoverflow.com/questions/4432748/what-does-attributeoverride-mean) – skaffman Mar 10 '11 at 14:44
  • i tried reading that but my doubts are not fully cleared –  Mar 10 '11 at 15:45
  • 2
    @Pasha: In which case you should mention that you read the other answers, and ask for clarification about them, and which specific points you didn't understand. If you just ask the same question again, you'll get the same answers again. – skaffman Mar 10 '11 at 15:57

1 Answers1

7

It is for specifying another name for the column in the table other than the one specified in your embedded class.

E.g. AttributeOverride

Ravi Parekh
  • 5,253
  • 9
  • 46
  • 58
xxtommoxx
  • 309
  • 3
  • 13
  • what does (name=firstname) and coumn (name=fld_firstname) signify –  Mar 10 '11 at 15:47
  • name is the variable in your embedded class column is what you want that variable to map to in the column for a table. In your example there will be a column fld_firstname in the table that uses this embedded class which maps to the variable firstName. – xxtommoxx Mar 10 '11 at 16:03
  • the thing which is confusing me is that fld_firstname and firstname are two separate columns in database in different tables or there is only one database table column with firstname –  Mar 10 '11 at 16:28
  • in your example it will be in one table the User table containing a column fld_firstname, you may also need to specify the mapping for lastname too. – xxtommoxx Mar 10 '11 at 16:36
  • what difference it makes if i don't use attributeoverride in above example –  Mar 10 '11 at 17:58