Hibernate field naming issue with Spring Boot (naming strategy)

后端 未结 6 915
粉色の甜心
粉色の甜心 2020-11-29 09:31

Note that this code does work with plain Spring but not with Spring Boot(v1.3.3), is there something i\'m missing because this is imported from a spring app that works. The

6条回答
  •  没有蜡笔的小新
    2020-11-29 09:33

    SINCE SPRING-BOOT 1.4

    Starting from 1.4, because of the switch to Hibernate 5, the naming strategy has been updated to SpringPhysicalNamingStrategy which should be very close to 1.3 defaults.

    See also:

    • Spring's naming strategy

    PREVIOUS VERSION

    Spring Boot provides the ImprovedNamingStrategy as default naming strategy, which makes Hibernate search for a team_id column (inferred from the int teamId field). As this column doesn't exist in your table, that's the cause of the error. From the Hibernate docs:

    An improved naming strategy that prefers embedded underscores to mixed case names

    You've got two options:

    1. Provide the column name explicitly as @Column(name="teamId"). There used to be a bug with this in early Boot versions, not anymore.

    2. Change the naming strategy in the Spring Boot properties and tell it to use the EJB3NamingStrategy, which doesn't convert camelCase to snake_case, but keeps it as it is.

提交回复
热议问题