Skip to content
Advertisement

use desc as a field name in Spring boot entity class

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

Advertisement

Answer

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;
}

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement