Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 液化酶&x2B;Spring数据:如何从JPA创建实体_Java_Spring_Hibernate_Jpa_Liquibase - Fatal编程技术网

Java 液化酶&x2B;Spring数据:如何从JPA创建实体

Java 液化酶&x2B;Spring数据:如何从JPA创建实体,java,spring,hibernate,jpa,liquibase,Java,Spring,Hibernate,Jpa,Liquibase,是否有可能从@Entity声明创建Liquibase脚本 我想要什么? 当我运行'gradle diffI supporte liquibase check时,数据库中没有表Owner,并在changelog`文件中创建记录,然后基于此记录在数据库中创建表 我尝试使用这个库: build.gradle: buildscript { dependencies { classpath "org.liquibase:liquibase-gradle-plugin:2.0.2"

是否有可能从@Entity声明创建Liquibase脚本

我想要什么? 当我运行'gradle diff
I supporte liquibase check时,数据库中没有表
Owner
,并在
changelog`文件中创建记录,然后基于此记录在数据库中创建表

我尝试使用这个库:

build.gradle:

buildscript {
    dependencies {
        classpath "org.liquibase:liquibase-gradle-plugin:2.0.2"
    }
}

plugins {
    id 'org.springframework.boot' version '2.2.2.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
    id "org.liquibase.gradle" version "2.0.2"
}

apply plugin: 'org.liquibase.gradle'

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    testImplementation('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
    compileOnly 'org.projectlombok:lombok'
    implementation 'org.liquibase:liquibase-core'
    runtimeOnly 'javax.xml.bind:jaxb-api'
    compile group: 'io.springfox', name: 'springfox-swagger2', version: swaggerVersion
    compile group: 'io.springfox', name: 'springfox-swagger-ui', version: swaggerVersion
    runtimeOnly 'mysql:mysql-connector-java'
    liquibaseRuntime 'org.liquibase:liquibase-core'
    liquibaseRuntime 'mysql:mysql-connector-java'
    liquibaseRuntime('org.liquibase.ext:liquibase-hibernate5:3.8')
    liquibaseRuntime('org.springframework.boot:spring-boot-starter')
    liquibaseRuntime('org.springframework.boot:spring-boot-starter-data-jpa')
    annotationProcessor 'org.projectlombok:lombok'
}


liquibase {
    activities {
        main {
            driver 'com.mysql.cj.jdbc.Driver'
            url 'jdbc:mysql://localhost:3306/homebudget'
            username 'user'
            password 'pass'
            changeLogFile 'src/main/resources/db/db.changelog-master.xml'
            defaultSchemaName 'homebudget'
            logLevel 'debug'
            changeLogFile 'src/main/resources/db/db.changelog-master.xml'
            referenceUrl 'hibernate:spring:com.homebudget.domain?dialect=org.hibernate.dialect.MySQL5Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy'
        }
    }
}
在我的项目中,我有一个实体:
com.homebutch.domain.Owner

@Getter
@Setter
@Entity
public class Owner extends BaseEntity {
    private String name;
}
当我运行
gradle diff
时,我收到一条消息:

Reference Database: null @ hibernate:spring:pl.homebudget.domain?dialect=org.hibernate.dialect.MySQL5Dialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy (Default Schema: HIBERNATE)
Comparison Database: user@172.21.0.1 @ jdbc:mysql://localhost:3306/homebudget (Default Schema: homebudget)
Compared Schemas: HIBERNATE -> homebudget
Product Name:
     Reference:   'Hibernate'
     Target: 'MySQL'
Product Version:
     Reference:   '5.4.9.Final'
     Target: '8.0.18'
Missing Catalog(s): NONE
Unexpected Catalog(s): NONE
Changed Catalog(s): 
     HIBERNATE
          name changed from 'HIBERNATE' to 'homebudget'
Missing Column(s): NONE
Unexpected Column(s): 
     homebudget.DATABASECHANGELOG.AUTHOR
     homebudget.DATABASECHANGELOG.COMMENTS
     homebudget.DATABASECHANGELOG.CONTEXTS
     homebudget.DATABASECHANGELOG.DATEEXECUTED
     homebudget.DATABASECHANGELOG.DEPLOYMENT_ID
     homebudget.DATABASECHANGELOG.DESCRIPTION
     homebudget.DATABASECHANGELOG.EXECTYPE
     homebudget.DATABASECHANGELOG.FILENAME
     homebudget.DATABASECHANGELOG.ID
     homebudget.DATABASECHANGELOGLOCK.ID
     homebudget.DATABASECHANGELOG.LABELS
     homebudget.DATABASECHANGELOG.LIQUIBASE
     homebudget.DATABASECHANGELOGLOCK.LOCKED
     homebudget.DATABASECHANGELOGLOCK.LOCKEDBY
     homebudget.DATABASECHANGELOGLOCK.LOCKGRANTED
     homebudget.DATABASECHANGELOG.MD5SUM
     homebudget.DATABASECHANGELOG.ORDEREXECUTED
     homebudget.DATABASECHANGELOG.TAG
Changed Column(s): NONE
Missing Foreign Key(s): NONE
Unexpected Foreign Key(s): NONE
Changed Foreign Key(s): NONE
Missing Index(s): NONE
Unexpected Index(s): 
     PRIMARY UNIQUE  ON homebudget.DATABASECHANGELOGLOCK(ID)
Changed Index(s): NONE
Missing Primary Key(s): NONE
Unexpected Primary Key(s): 
     PRIMARY on homebudget.DATABASECHANGELOGLOCK(ID)
Changed Primary Key(s): NONE
Missing Sequence(s): NONE
Unexpected Sequence(s): NONE
Changed Sequence(s): NONE
Missing Table(s): NONE
Unexpected Table(s): 
     DATABASECHANGELOG
     DATABASECHANGELOGLOCK
Changed Table(s): NONE
Missing Unique Constraint(s): NONE
Unexpected Unique Constraint(s): NONE
Changed Unique Constraint(s): NONE
Missing View(s): NONE
Unexpected View(s): NONE
Changed View(s): NONE
19:52:21.564 INFO  [liquibase.integration.commandline.Main]: Liquibase command 'diff' was executed successfully.

从liquibase hibernate文档中,您可以看到,当插件使用hbm2java来帮助检测差异时,它在生产中是不好的。如果您不需要为许多实体提供支持,那么最好是手工操作。