markdown JHipster实体更新

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown JHipster实体更新相关的知识,希望对你有一定的参考价值。

# Official Workflow
Here is the development workflow:
- Modify your JPA entity (add a field, a relationship, etc.)
- Compile your application (this works on the compiled Java code, so don’t forget to compile!)
- Run `./mvnw liquibase:diff` (or `./mvnw compile liquibase:diff` to compile before)
- A new “change log” is created in your `src/main/resources/config/liquibase/changelog` directory
- Review this change log and add it to your `src/main/resources/config/liquibase/master.xml` file, so it is applied the next time you run your application

If you use Gradle instead of Maven, you can use the same workflow by running `./gradlew liquibaseDiffChangelog -PrunList=diffLog`, 
and change the database configuration in build.gradle in the liquibase configuration if required.

# Creating/Editing an Entity
There are 2 main options to create/edit an entity. It is possible to use *jhipster*'s entity manager 
or create/edit and import an jhioster *.jdl* using [JDLStudio](https://start.jhipster.tech/jdl-studio).

- checkout [JHipster documentation](https://www.jhipster.tech/creating-an-entity/) on creating entities.

### [JDL Studio](https://start.jhipster.tech/jdl-studio)
- Create/Edit the entity
- Download the *jdl* file
- import the file on terminal, paying attention to the selected options.
**important**: Don't override *liquibase files* if you´re plannning in migrate your database. If you're on early stages of development, fell free to override all files.
```
jhipster import-jdl {filename}
```
- The following proceedings will depend if you want to maintain the db or start with a clean one

### JHipser Entity Creation
Follow [JHipster inscrutions](https://www.jhipster.tech/creating-an-entity/) about how to use the tool.

### Proceedings after an entity is updated
Once the editing process is completed, it is neecessary to address the database changes on **liquibase**.
It is important to notice that **jhipster doesn't manage this kind of database change automatically**.

You must decide if it is necessary to **migrate** the database or if it may be **dropped**.

### Maintaining the DB
To migrate the database, it is necessary to create a **liquibase changelog**, to inform liquibase about *database changes*, 
making the appropriate modification, like inserting standard values in certain fields.
- on terminal, call `./gradlew liquibaseDiffChangeLog`
- a file with a new *changelog* will be created in `src\main\resources\config\liquibase\changelog`
- the file must be added to `master.xml`, located on `src\main\resources\config\liquibase\`
- add the file at the base of the `master.xml`


### Dropping the database
Considering that the database was changed using some of the jhipster system, call on terminal
- `./gradlew clean` to wipe out the data
- `./gradlew liquibaseClearChecksums` to clear liquibase checksums, validating the changed changelogs


### Adding to cache
When using cache, it may be necessary to update `CacheConfiguration.java`, including new entities and its foreign keys.
Notice the `@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)` annotation in the entity class.
``` java
@ApiModel(description = "Pesquisa completa")
@Entity
@Table(name = "pesquisa")
\!h // using cache for entity
\!h @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Pesquisa implements Serializable {

  @OneToMany(mappedBy = "pesquisa")
  @JsonIgnore
\!h  // using cache for foreign key
\!h  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  private Set<AgeGroup> ageGroup = new HashSet<>();
}
```
The cache configuration must be updated.
``` java
@Configuration
@EnableCaching
@AutoConfigureAfter(value = { MetricsConfiguration.class })
@AutoConfigureBefore(value = { WebConfigurer.class, DatabaseConfiguration.class })
public class CacheConfiguration {
  // ...
  @Bean
    public JCacheManagerCustomizer cacheManagerCustomizer() {
        return cm -> {
          // ...
          \!h cm.createCache(br.com.pixinside.arcelor.linhadotempo.futuro.domain.Pesquisa.class.getName(), jcacheConfiguration);
          \!h cm.createCache(br.com.pixinside.arcelor.linhadotempo.futuro.domain.Pesquisa.class.getName() + ".ageGroup", jcacheConfiguration);
          // ...
        }
}
```

以上是关于markdown JHipster实体更新的主要内容,如果未能解决你的问题,请参考以下文章

markdown JHipster - 在Angular上导入模块

markdown jhipster

markdown JHipster - 增加分页

markdown JHipster - 创建和运行Docker镜像

markdown JHipster上的角度材料

markdown JHipster JWT认证