Home > AI > Backend > SpringBoot > mysql-connector-java >

@Table

@Entity

@Table(name=”Student”)

public class Student {  

…  

}

Attribute:

Name: The name of the table. It is an optional attribute.

Without table

@Data
@NoArgsConstructor
@Entity
public class Employee {
    @Id
    @GeneratedValue
    public Long id;


    @Column(name="name")
    public String firstname;
}

The table name is automatically generated.

And, if you refractor the class, the same problem happend in @Column(name=) will appear here again.

@Data
@NoArgsConstructor
@Entity
public class MyEmployee {
    @Id
    @GeneratedValue
    public Long id;


    @Column(name="name")
    public String firstname;
}

The old will be kept, while you have a new one.

With @Table

@Data
@NoArgsConstructor
@Entity
@Table(name="employee")
public class MyEmployee {
    @Id
    @GeneratedValue
    public Long id;


    @Column(name="name")
    public String firstname;
}

You can fix the name of database table

Leave a Reply