Hibernate field naming issue with Spring Boot (naming strategy) -


note code work plain spring not spring boot(v1.3.3), there i'm missing because imported spring app works. code below spring boot app

@entity @table(name="project") public class project implements serializable{      private static final long serialversionuid = 1l;      @id     @generatedvalue(strategy=generationtype.auto)     @column(name="id")     private int id;      @column(name="teamid")     private int teamid;      //private string rentabiliteit;      @column     //@index(name="iproject_status",columnnames="status")     private string status;      @column     //@index(name="iproject_naam",columnnames="naam")     private string naam;     //public prototype m_prototype;     //public team m_team;  } 

sql

create table if not exists `project` ( `id` int(11) not null, `teamid` int(11) default null, `status` varchar(255) default null, `naam` varchar(255) default null  ) engine=innodb auto_increment=43 default charset=latin1; 

error

caused by: com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception:             unknown column 'project0_.team_id' in 'field list' 

edited: application.yml

spring:  mvc:   view:     prefix: /web-inf/jsp/     suffix: .jsp  datasource:     url: jdbc:mysql://localhost:3306/oxyplast     username: oxyplastuser     password: oxyplastuserpw  jpa:   properties:     hibernate:       current_session_context_class: org.springframework.orm.hibernate4.springsessioncontext        namingstrategy: org.hibernate.cfg.defaultnamingstrategy 

spring boot provides improvednamingstrategy default naming strategy, makes hibernate search team_id column (inferred int teamid field). column doesn't exist in table, that's cause of error. hibernate docs:

an improved naming strategy prefers embedded underscores mixed case names

you've got 2 options:

  1. provide column name explicitly @column(name="teamid"). there used bug in boot versions, not anymore.

  2. change naming strategy in spring boot properties , tell use ejb3namingstrategy, doesn't convert camelcase snake_case, keeps is.


update

starting 1.4, because of switch hibernate 5, naming strategy has been updated springphysicalnamingstrategy should close 1.3 defaults.

see also:


Comments