I'm working on a Spring Boot application using Hibernate and Lombok. I have an entity class Product mapped to a product table in my database. Here's the relevant part of the code:
@Entity
@Table(name = "product")
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ProductId")
private int id;
// Other fields...
}
When I run my application, I get the following error:
ERROR o.h.engine.jdbc.spi.SqlExceptionHelper : Unknown column 'p1_0.product_id' in 'field list'
It seems like Hibernate is converting the camel-case field name 'ProductId' in my entity class to the underscore-separated column name 'product_id' in the database, causing a mismatch.
I tried changing the @Column annotation to match the actual column name in the database, but it didn't solve the issue. I also checked my database schema and it does have a 'ProductId' column.
Is there a way to change the Hibernate naming strategy so that it doesn't automatically convert the field names? I want the names in my entity class to directly map to the column names in the database without any modifications.