简体   繁体   English

我如何使用休眠在mysql集群中创建表

[英]how do i create table in mysql cluster using hibernate

I am using the hibernate with spring boot and table created in given database but not in another database like 10.10.1.350 is management node and 10.10.1.348 and 10.10.1.349 are child db. 我正在使用带有弹簧启动的休眠模式,并在给定的数据库中创建表,但在另一个数据库(例如10.10.1.350是管理节点)和10.10.1.348和10.10.1.349是子数据库中却没有使用。 when we create table using query directly in 348 then table auto created in 349. But we are using the hibernate then table created in 348 but not auto create in 349. 当我们直接在348中使用查询创建表时,然后在349中自动创建表。但是,我们使用的是休眠然后在348中创建的表,但没有在349中自动创建表。

Properties like:- 属性如:-

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url=jdbc:mysql://10.10.1.348:3306/test
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=abc@1234
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect 

Pojo Class- Pojo Class-

@Entity
@Table(name = "test")
@Getter
@Setter
public class Test {

    @Id
    @Column(name = "tst_id")
    private Long tstId;
    @Column(name = "tst_nm")
    private String tstNm;


}

pom.xml for mysql dependency- mysql依赖项的pom.xml

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>

        </dependency>

Hibernate docs says : 休眠文档说

Although Hibernate provides the update option for the hibernate.hbm2ddl.auto configuration property, this feature is not suitable for a production environment. 尽管Hibernate为hibernate.hbm2ddl.auto配置属性提供了update选项,但是此功能不适用于生产环境。

Just use Flyway or Liquibase for DB migrations. 只需使用Flyway或Liquibase进行数据库迁移。 Spring boot integrates with both of them . Spring Boot与它们两者集成

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM