Home > Software engineering >  How does JPA map a column name to a field if the column name is different than the field name?
How does JPA map a column name to a field if the column name is different than the field name?

Time:10-23

Suppose I have a table Students which has columns varchar firstname and varchar lastname.

For some reason my Entity Class has fields with different names, say String fname and String lname.

So how does JPA correctly map the column with the field?

CodePudding user response:

You may use the @Column annotation, e.g.

@Entity(name="Students")
public class Students {
    @Column(name = "firstname")
    private String fname;

    @Column(name = "lastname")
    private String lname;
}
  • Related