0

We are trying to migrate our microservice to Spring Boot 2, currently, we are using Spring Boot 1.5.6.RELEASE.

During the migration process we recognized that our microservice is partially broken, in the log files we found the following error:

com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'acme_ms.hibernate_sequence' doesn't exist

Only one domain class exists in our application at the moment:

@Getter
@Setter
@ToString
@Entity
@Table(name = "acme_ms_card_details")
public class CardDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String cardType;
}

and we found that the issue related to GeneratedValue strategy type, we tried to change strategy to GenerationType.IDENTITY and the error disappeared.

So, the question that we have for now: Why with Spring boot 1.5 GenerationType.AUTO works perfectly well but after migration to Spring boot 2, GenerationType.AUTO doesn't work at all.

What was critically changed?

Note: as a Database, we are using MySQL.

user471011
  • 7,104
  • 17
  • 69
  • 97

2 Answers2

4

Spring Boot 1.5.6 uses Hibernate 5.0.12.Final while Spring Boot 2 uses Hibernate 5.2.12.Final and that new Hibernate version has a change which breaks strategy = GenerationType.AUTO.

You need to add the following property hibernate.id.new_generator_mappings to true to restore backwards compatibility.

hibernate 5 sequencegenerator not giving the right value

Ivan
  • 8,508
  • 2
  • 19
  • 30
  • 1
    also found this article: https://www.thoughts-on-java.org/5-things-you-need-to-know-when-using-hibernate-with-mysql/ where the author advises to define @GenericGenerator. – user471011 Aug 22 '18 at 20:05
1

You need to change @GeneratedValue(strategy = GenerationType.AUTO) to @GeneratedValue(strategy = GenerationType.IDENTITY).

BeUndead
  • 3,463
  • 2
  • 17
  • 21
Edgardo Genini
  • 653
  • 5
  • 11