春天启动与休眠,我不能用下划线拿走表名

时间:2017-02-06 19:52:02

标签: hibernate jpa spring-boot

我已经尝试了application.properties中的所有替代方法(见下文)我到目前为止已找到但是我的应用程序仍然使用" _"而不是我设置的驼峰案例。

任何建议都将受到高度赞赏。

1 
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.cfg.DefaultNamingStrategy

output
DefaultNamingStrategy cannot be cast to org.hibernate.boot.model.naming.ImplicitNamingStrategy

2
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.cfg.DefaultNamingStrategy
output
org.hibernate.cfg.DefaultNamingStrategy cannot be cast to org.hibernate.boot.model.naming.PhysicalNamingStrategy

3
spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.DefaultNamingStrategy
output
org.hibernate.SQL                        : drop table tipo_dominio if exists
NOTE: no error but I didn't get the table name without "_"

4
spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.EJB3NamingStrategy
output
EJB3NamingStrategy cannot be cast to org.hibernate.boot.model.naming.PhysicalNamingStrategy

我的实体

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;




@Entity(name="TipoDominio")
@Table(name="TipoDominio")
public class TipoDominio implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue
    private Long id;

POM

    <properties>
        <main.basedir>${basedir}/../..</main.basedir>

        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>


        <!-- Compile -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
            <version>1.5.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>1.5.1.RELEASE</version>
        </dependency>
        <!-- Runtime -->
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
            <version>1.4.193</version>
        </dependency>
        <!-- Test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>1.5.1.RELEASE</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

***编辑 我试过了

@SpringBootApplication(exclude={HibernateJpaAutoConfiguration.class

也没有成功

2 个答案:

答案 0 :(得分:3)

使用SpringBoot 1.5.x,hibernate版本为&#34; 5.x&#34;。这意味着没有下划线的表的命名策略类已更改。这应该适用于你拥有的东西。

spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

请注意,配置属性名称以及类更改。

答案 1 :(得分:0)

可能它是这样做的,因为它创建没有引号的表,对于h2表示不区分大小写的标识符。您是否需要区分大小写的标识符?