entity class and database column naming conventions - jamongx/twitter-clone GitHub Wiki

Java Entity Class Naming:

  • Use CamelCase for naming member variables in Java entity classes. This means starting each word within the variable name with an uppercase letter, except for the first word.
  • Examples: firstName, lastName.

Database Column Naming:

  • Use snake_case for naming database columns. This involves writing all characters in lowercase and separating words with underscores (_).
  • Examples: first_name, last_name.

When using Spring Data JPA, if there's a difference between the entity class field name and the database column name, the @Column annotation must be used to explicitly define the mapping.

For instance:

@Entity
public class User {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "first_name")
    private String firstName;

    @Column(name = "last_name")
    private String lastName;
    // other fields...
}

In this example, the firstName field is mapped to the first_name column in the database.