1

I'm working on a Spring Boot project using Spring Data JPA + Hibernate for data access, but I'm having a strange problem.

In my Entity class I specified these columns:

@Entity
@Table(name = "Subjects")
public class Subject {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    private String name;
    @Column(name="InsertionDate")
    private Date insertDate;

    // get + set...
}

When I try to execute repo.findAll() I get this exception:

com.microsoft.sqlserver.jdbc.SQLServerException: Invalid column name 'insertion_date'.

What's wrong in my configuration? Why is Hibernate searching for 'insertion_date' instead of 'InsertionDate'? How can I configure the right column name?

davioooh
  • 23,742
  • 39
  • 159
  • 250

1 Answers1

1

In SpringBoot the @Column(name="") annotation is ignored unless you set an application property to use a different naming class.

If you don't have an application.properties, make a file by that name in your src/main/resources directory. Add the line:

spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy

In it and your naming will work as you want it.

Reference: Spring Boot + JPA : Column name annotation ignored

Community
  • 1
  • 1
K.Nicholas
  • 10,956
  • 4
  • 46
  • 66