Skip to content
Advertisement

Spring Boot Hibernate creates tables with wrong names

When I run my project, the Hibernate creates automatically tables with wrong names. I have two tables User and Role and also three classes: abstract class IdField.java:

JavaScript

User.java class:

JavaScript

and Role.java class:

JavaScript

And Hibernate creates two tables with wrong names as id_field and id_field_roles: enter image description here

but I want table names as it is in @Table annotation like “user” and “role”

Advertisement

Answer

Get familiar with inheritance strategies:

https://thorben-janssen.com/complete-guide-inheritance-strategies-jpa-hibernate/

It seems to me you are looking for @MappedSuperclass

If you just want to share state and mapping information between your entities, the mapped superclass strategy is a good fit and easy to implement. You just have to set up your inheritance structure, annotate the mapping information for all attributes and add the @MappedSuperclass annotation to your superclass. Without the @MappedSuperclass annotation, Hibernate will ignore the mapping information of your superclass.

On top of that: If your shared part is only id field, as the name suggests, inheritance looks like overkill.

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