Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
365 views
in Technique[技术] by (71.8m points)

java - Hibernate naming strategy changing table names

I'm a little bit confused by hibernates (version 5.1) naming strategy - namely it changes my table name and I'd like to avoid that. Also - spring.jpa.hibernate.naming_strategy seems to be deprecated according to intelij, but I can't find a (nother) way of configuring it correctly.

I have the following configuration in application.properties:

spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.EJB3NamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.jpa.properties.hibernate.current_session_context_class=thread

The first one is marked as depracted, as said.

Now I have an entity:

@Entity
@Table(name = "usaUploadTable", schema = "usertable201", catalog = "")
public class UsaUploadTable {
    ....
}

The table name is, like in @Table(name = "") usaUploadTable.

Now when I run my application, I get

Table 'usertable201.usa_upload_table' doesn't exist

which is correct - it isn't named like how hibernate is changing it.

What can I do to make hibernate use my table name correctly?

Edit:

I've also tried

DefaultNamingStrategy
ImprovedNamingStrategy

All of them change it

Versions:

spring-boot-1.4.0.RELEASE
hibernate 5.1
javax-transaction-api 1.2
hibernate-validator 5.2.4
javassist 3.20
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

it worked for me. here are the versions i'm using:

Spring Boot (v1.4.2.RELEASE)
Hibernate Core {5.0.11.Final}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...