Home > Software design >  use desc as a field name in Spring boot entity class
use desc as a field name in Spring boot entity class

Time:10-03

The table was not being created for the following model despite following the correct procedure Model

  @AllArgsConstructor
    @NoArgsConstructor
    @Data
    @Entity
    public class Product {
    
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        Integer pid;
    
        String name;
        String desc;
        double price;
    }

enter image description here

CodePudding user response:

So I was creating an entity class for JPA where there was a field name desc. I was using MySQL database. But for some reason, I was getting the following error. The model

@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class Product {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    Integer pid;

    String name;
    String desc;
    double price;
}

enter image description here

Later I changed the field name and the whole thing was working. The ORM was automatically creating the table. The updated model that works

@AllArgsConstructor
@NoArgsConstructor
@Data
@Entity
public class Product {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    Integer pid;

    String name;
    String description;
    double price;
}
  • Related