jhipster在现有实体中添加新属性

时间:2017-02-09 10:25:03

标签: spring spring-boot jhipster

我正在使用jhipster 4.0.0并且我fisrt创建了两个实体

@Entity
@Table(name = "branch")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Branch implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "branchname")
    private String branchname;

    @Column(name = "branchaddress")
    private String branchaddress;

    @ManyToOne
    private Organization organization;

    //geter()
    //setter()

    }

>yo jhipster:entity organization
? Do you want to update the entity? This will replace the existing files for this entity, all your custom code will be overwritten Yes, add more fields and relationshi

================= Organization =================
Fields
orgname (String)
orgaddress (String)

Relationships
branch (Branch) one-to-many


Generating field #3

? Do you want to add a field to your entity? Yes
? What is the name of your field? active
? What is the type of your field? String
? Do you want to add validation rules to your field? No

================= Organization =================
Fields
orgname (String)
orgaddress (String)
active (String)

Relationships
branch (Branch) one-to-many


Generating field #4

? Do you want to add a field to your entity? No

================= Organization =================
Fields
orgname (String)
orgaddress (String)
active (String)

Relationships
branch (Branch) one-to-many


Generating relationships to other entities

? Do you want to add a relationship to another entity? No

================= Organization =================
Fields
orgname (String)
orgaddress (String)
active (String)

Relationships
branch (Branch) one-to-many



 conflict .jhipster\Organization.json
? Overwrite .jhipster\Organization.json? overwrite
    force .jhipster\Organization.json
 conflict src\main\resources\config\liquibase\changelog\20170209093838_added_entity_Organization.xml
? Overwrite src\main\resources\config\liquibase\changelog\20170209093838_added_entity_Organization.xml? overwrite
    force src\main\resources\config\liquibase\changelog\20170209093838_added_entity_Organization.xml
 conflict src\main\java\com\icarat\domain\Organization.java
? Overwrite src\main\java\com\icarat\domain\Organization.java? overwrite
    force src\main\java\com\icarat\domain\Organization.java
identical src\main\java\com\icarat\repository\OrganizationRepository.java
identical src\main\java\com\icarat\web\rest\OrganizationResource.java
identical src\main\java\com\icarat\service\OrganizationService.java
identical src\main\java\com\icarat\service\impl\OrganizationServiceImpl.java
 conflict src\main\java\com\icarat\service\dto\OrganizationDTO.java
? Overwrite src\main\java\com\icarat\service\dto\OrganizationDTO.java? overwrite
    force src\main\java\com\icarat\service\dto\OrganizationDTO.java
identical src\main\java\com\icarat\service\mapper\OrganizationMapper.java
 conflict src\test\java\com\icarat\web\rest\OrganizationResourceIntTest.java
? Overwrite src\test\java\com\icarat\web\rest\OrganizationResourceIntTest.java? do not overwrite
     skip src\test\java\com\icarat\web\rest\OrganizationResourceIntTest.java
identical src\main\resources\config\liquibase\master.xml
identical src\main\resources\ehcache.xml
 conflict src\main\webapp\app\entities\organization\organization.component.html
? Overwrite src\main\webapp\app\entities\organization\organization.component.html? do not overwrite
     skip src\main\webapp\app\entities\organization\organization.component.html
 conflict src\main\webapp\app\entities\organization\organization-detail.component.html
? Overwrite src\main\webapp\app\entities\organization\organization-detail.component.html? overwrite
    force src\main\webapp\app\entities\organization\organization-detail.component.html
 conflict src\main\webapp\app\entities\organization\organization-dialog.component.html
? Overwrite src\main\webapp\app\entities\organization\organization-dialog.component.html? do not overwrite

这两个工作正常现在我将名为Active的新属性添加到组织实体,如

liquibase.exception.ValidationFailedException: Validation Failed:
     1 change sets check sum
          classpath:config/liquibase/changelog/20170209093838_added_entity_Organization.xml::20170209093838-1::jhipster was: 7:2b47689e3924d85d502e6150230cd184 but is now: 7:74e4a48710ed8eaf27e2a0231f7d23a9

当我运行我的项目时 ./mvnw

它显示错误,如

Settings
----------------------------
[INFO]     driver: com.mysql.jdbc.Driver
[INFO]     url: jdbc:mysql://localhost:3306/jhipster2
[INFO]     username: root
[INFO]     password: *****
[INFO]     use empty password: false
[INFO]     properties file: null
[INFO]     properties file will override? false
[INFO]     prompt on non-local database? true
[INFO]     clear checksums? false
[INFO]     changeLogFile: src/main/resources/config/liquibase/master.xml
[INFO]     context(s): null
[INFO]     label(s): null
[INFO]     referenceDriver: null
[INFO]     referenceUrl: hibernate:spring:com.icarat.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
[INFO]     referenceUsername: null
[INFO]     referencePassword: null
[INFO]     referenceDefaultSchema: null
[INFO]     diffChangeLogFile: src/main/resources/config/liquibase/changelog/20170209102144_changelog.xml
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.058 s
[INFO] Finished at: 2017-02-09T15:51:48+05:30
[INFO] Final Memory: 18M/49M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.liquibase:liquibase-maven-plugin:3.5.3:diff (default-cli) on project jhipster-2: Error setting up or running Liquibase: liquibase.exception.DatabaseException: java.sql.SQLException: Access denied for user 'root'@'localhost' (using password: NO) -> [Help 1]

我也尝试了所有解决方案

How to modify existing entity generated with jhipster?

当我运行mvn liquibase:更改后的差异我就像这样

interface Dish {
      Name: string;
      Description: string;
      Thumbnail: string;
}

interface Category {
      [name: string]: Dish;
}

type ServerResponse = {
      [name: string]: { [name: string]: Category; } & { name: string };
}

任何人都可以帮助我

2 个答案:

答案 0 :(得分:1)

您需要设置数据库用户名& pom.xml中的liquibase-maven-plugin密码

答案 1 :(得分:0)

当我们更改数据库用户名& pom.xml中的liquibase-maven-plugin密码。

 <plugin>
                    <groupId>org.liquibase</groupId>
                    <artifactId>liquibase-maven-plugin</artifactId>
                    <version>${liquibase.version}</version>
                    <configuration>
                        <changeLogFile>src/main/resources/config/liquibase/master.xml</changeLogFile>
                        <diffChangeLogFile>src/main/resources/config/liquibase/changelog/${maven.build.timestamp}_changelog.xml</diffChangeLogFile>
                        <driver>com.mysql.jdbc.Driver</driver>
                        <url>jdbc:mysql://localhost:3306/jhipsternew</url>
                        <defaultSchemaName>jhipsternew</defaultSchemaName>
                        <username>root</username>
                        <password>################</password>
                        <referenceUrl>hibernate:spring:com.icarat.domain?dialect=org.hibernate.dialect.MySQL5InnoDBDialect&amp;hibernate.physical_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy&amp;hibernate.implicit_naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy</referenceUrl>
                        <verbose>true</verbose>
                        <logging>debug</logging>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.javassist</groupId>
                            <artifactId>javassist</artifactId>
                            <version>3.18.2-GA</version>
                        </dependency>
                        <dependency>
                            <groupId>org.liquibase.ext</groupId>
                            <artifactId>liquibase-hibernate5</artifactId>
                            <version>${liquibase-hibernate5.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-starter-data-jpa</artifactId>
                            <version>${project.parent.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>javax.validation</groupId>
                            <artifactId>validation-api</artifactId>
                            <version>1.1.0.Final</version>
                        </dependency>
                    </dependencies>
                </plugin>
之后我们必须运行

./mvnw liquibase:clearCheckSums



./mvn liquibase:diff

之后,在我们的src / main / resources / config / liquibase / changelog目录中创建了新的“更改日志”。该目录中的文件以其创建日期为前缀(以yyyyMMddHHmmss格式),然后有一个标题描述它们的作用。例如,20141006152300_added_price_to_product.xml是一个好名字。在src / main / resources / config / liquibase / master.xml文件中添加此“更改日志”文件,以便下次运行应用程序时应用该文件如果您想了解有关使用Liquibase的更多信息