0

I'm having trouble to get my unit test working with the CrudRepository.save method. When I run my unit test it keeps running forever, not going past the save() method.

The last DEBUG message that appears in my console is:

16:20:35.293 [main] DEBUG org.hibernate.loader.Loader - Done entity load

Now the weird part is that it is working if I execute one insert statement using the old JdbcTemplate, ONLY if the primary key is 1.
So for example;
INSERT INTO my_table (id, value) VALUES (1, 'Hello World')
Will work, and the test will succeed
But this will not:
INSERT INTO my_table (id, value) VALUES (2, 'Hello World')
And the test keeps running forever

Already been looking for something like auto_increment not setup right, but I couldn't find anything.

Jelle den Burger
  • 1,428
  • 17
  • 31

1 Answers1

1

Okay, so I found out that I needed to use a different value for the @GeneratedValue annotation for my auto incremented variable.

I used the first value from this answer: https://stackoverflow.com/a/4103347/5976604 and it worked afterwards.

@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
private Long id;

I do think that it's annoying that Hibernate does not throw an exception or something when this occurs, but instead it gets stuck.

Community
  • 1
  • 1
Jelle den Burger
  • 1,428
  • 17
  • 31