Good day, I'm learning spring. I see several options for working with the entity. I can't understand if there is any difference between these 2 methods.
First
@Entity
@NoArgsConstructor
@EqualsAndHashCode
public class ProductTest {
private Long idProduct;
private String nameProduct;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_product", table = "product", nullable = false)
public Long getIdProduct() {
return idProduct;
}
public void setIdProduct(Long idProduct) {
this.idProduct = idProduct;
}
@Basic
@Column(name = "name_product", table = "product", nullable = false, length = 100)
public String getNameProduct() {
return nameProduct;
}
public void setNameProduct(String nameProduct) {
this.nameProduct = nameProduct;
}
}
Second
@Entity
@NoArgsConstructor
@EqualsAndHashCode
public class ProductTest {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id_product", table = "product", nullable = false)
private Long idProduct;
@Basic
@Column(name = "name_product", table = "product", nullable = false, length = 100)
private String nameProduct;
public Long getIdProduct() {
return idProduct;
}
public void setIdProduct(Long idProduct) {
this.idProduct = idProduct;
}
public String getNameProduct() {
return nameProduct;
}
public void setNameProduct(String nameProduct) {
this.nameProduct = nameProduct;
}
}
What would be better for working with the database?
Also interested in whether I can add columns to tables via Entity and how? I will be glad to hear your advice.