Renaming tables and attributes

So far we assumed that we map classes to database tables having identical names: A Java class User is being mapped to a relational table with identical name User. Sometimes a renaming is desired. We may for example want to access a legacy database by a newly implemented Java application. Choosing meaningful names may conflict with decisions being taken when the original database design took place.

In the following example we change the database tables name from its default User to Person ❶. The properties uidNummber and cname are changed to attribute names numericUid ❷and fullName ❸ respectively:

package hibintro.v8;
@Table(name="Person") public class User {

    int uidNumber;
    @Column(name="numericUid") public int getUidNumber() {return uidNumber;}
    public void setUidNumber(int uidNumber) {this.uidNumber = uidNumber;}

    String uid;
    public String getUid() {return uid;}
    public void setUid(String uid) {this.uid = uid;}

    String cname;
    @Column(name="fullName", nullable = false) public String getCname() {return cname;}
    public void setCname(String cname) {this.cname = cname;}
   numericUid int(11) NOT NULL PRIMARY KEY,
   fullName varchar(255) NOT NULL,
   uid varchar(255) NOT NULL