Skip to content
Advertisement

Hibernate – make id value be able to be autogenerated directly in datasource as well

I’m making a Spring boot application with Hibernate ORM framework.

I have an @Entity class in my code:

I successfully can persist a Thing to my datasource. And thing_id is generated as expected.

But I cannot insert a record directly in database manager (e.g. DataGrip):

I have a warning and appropriate error when trying to insert:

So how can I make a column value autogenerated during insertion directly in database manager?

Advertisement

Answer

If you have a numeric column that you want to auto-increment, it might be an option to set columnDefinition directly. This has the advantage, that the schema auto-generates the value even if it is used without hibernate. This might make your code db-specific though:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement