0

I'm facing an issue while working with JPA entities in my Spring Boot application. I have an entity class named DriverMaster with the @Entity and @Table(name = "driverMaster") annotations to specify the desired table name. However, when the table is created in the database, it's being named as driver_master instead of driverMaster.

Here's my DriverMaster entity class:

@Entity
@Table(name = "driverMaster")
@Data
public class DriverMaster {
     // Attributes and getters/setters
}

I have used these properties

#spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
#spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.EJB3NamingStrategy
#spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
#spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.DefaultNamingStrategy

but nothing works!!!

  • Try with either lower case or upper case only ad table name – G10 Aug 18 '23 at 12:14
  • But i need to use driverMaster only, cant make it uppercase or lowercase. – sandeep kande Aug 18 '23 at 12:19
  • 2
    [This](https://stackoverflow.com/questions/29087626/entity-class-name-is-transformed-into-sql-table-name-with-underscores) might help. – Andrew S Aug 18 '23 at 12:35
  • Have you checked the db dialect? It affects the way Hibernate generates SQL statements so maybe the table names too – tamtejszystan Aug 18 '23 at 13:03
  • I'm using spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect – sandeep kande Aug 18 '23 at 13:06
  • Does this answer your question? [Entity Class name is transformed into SQL table name with underscores](https://stackoverflow.com/questions/29087626/entity-class-name-is-transformed-into-sql-table-name-with-underscores) – Dimitris Aug 18 '23 at 13:14
  • Hi @Dimitris it didn't solve my problem. – sandeep kande Aug 18 '23 at 13:23
  • @sandeepkande what did you do and did not work? As described spring splits camel case convention to underscore convention depending in the hibernate version `spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.EJB3NamingStrategy` or `spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl` Should fix it – Dimitris Aug 18 '23 at 13:31
  • What database do you use and version? Also what spring boot version do you use? – Dimitris Aug 18 '23 at 13:36
  • I see that you use lombok, remove the data annotation it might also be the root of issues you can use 'Getter' and 'Setter' but overriding the equals on entity might cause issues – Dimitris Aug 18 '23 at 13:39
  • Silly question, but are you sure the properties being picked up by Spring/Hibernate? I'd make sure this properties file actually affects your JPA context. Check you don't have something else defined in a persistence.xml or persistence property you are passing in via code. Otherwise, PhysicalNamingStrategyStandardImpl should be the only one you need to set. See https://www.baeldung.com/hibernate-field-naming-spring-boot for details – Chris Aug 18 '23 at 15:32
  • @Chris , I have checked with all the above mentioned properties one by one and PhysicalNamingStrategyStandardImpl giving tables with all small case, checked twice with same property. – sandeep kande Aug 21 '23 at 06:58
  • @Dimitris , working with java 1.8 , SpringBoot 2.7.14, MySQL 8.0.30, and Eclipse Version: 2023-03 (4.27.0) Build id: 20230309-1520 – sandeep kande Aug 21 '23 at 07:02
  • @sandeepkande did you try to remove the Data annotation? – Dimitris Aug 21 '23 at 09:55

0 Answers0