在jhipster中更新实体时的正确解决方法是什么?

时间:2015-08-28 18:59:52

标签: java spring maven jhipster

我有一个modelio UML类模型。我一直在更新它,之后我运行jhipster-uml .xmi来重新生成实体。我总是最终得到错误消息。我试图从-jhipster文件中删除entity.json文件,但它没有帮助。那么你能告诉我在开发过程中更新实体的正确解决方法是什么?我试图运行maven:diff任务,但没有运气。

编辑:

我创建了一个新的jhipster应用程序并从modelio UML类模型创建了实体。一切都很好。然后我只是在我的模型中添加了一个属性,然后从xmi文件中重新生成实体,并再次破坏所有内容。

我的工作流程是: 1)将uml模型保存为xmi文件 2)运行jhipster-uml ac2.xmi -paginate 3)在intellijIdea中编译我的应用程序 4)运行maven任务:mvn编译liquibase:diff创建一个新的changelog 5)运行应用程序 6)观察错误消息:

1 change sets check sum
      classpath:config/liquibase/changelog/20150828220237_added_entity_Employee.xml::20150828220237::jhipster is now: 7:dd10f74a01a95b4e48c592e796a1d352

部分错误:

[DEBUG] com.acontrol.config.DatabaseConfiguration - Configuring Datasource
[DEBUG] com.acontrol.config.DatabaseConfiguration - Configuring Liquibase
[ERROR] org.springframework.boot.context.embedded.tomcat.TomcatStarter - Error starting Tomcat context: org.springframework.beans.factory.BeanCreationException
[WARN] org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:133) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:474) ~[spring-context-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at com.acontrol.Application.main(Application.java:72) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_05]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_05]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_05]
    at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_05]
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) [idea_rt.jar:na]
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:98) ~[spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:75) ~[spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:378) ~[spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:155) ~[spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:157) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:130) [spring-boot-1.2.5.RELEASE.jar:1.2.5.RELEASE]
    ... 10 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration.setFilterChainProxySecurityConfigurer(org.springframework.security.config.annotation.ObjectPostProcessor,java.util.List) throws java.lang.Exception; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.core.userdetails.UserDetailsService com.acontrol.config.SecurityConfiguration.userDetailsService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDetailsService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.acontrol.repository.UserRepository com.acontrol.security.UserDetailsService.userRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository': Cannot create inner bean '(inner bean)#5550ca83' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#5550ca83': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303) ~[spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[s

3 个答案:

答案 0 :(得分:3)

当我想要重新生成所有表格时,我这样做

  1. 更新MODELIO
  2. 中的模型
  3. 重新导出xmi
  4. rm -rf ./.jhipster/
  5. 打开文件src/main/resources/config/liquibase/master.xml并删除所有<include>个元素
    • config/liquibase/changelog/00000000000000_initial_schema.xml
    • 评论“JHipster将在此处添加liquibase更改日志”
  6. 有时我必须从表格ID ='00000000000001'
  7. 中删除第一行(DATABASECHANGELOG}除外)
  8. 重新运行jhipster-uml

答案 1 :(得分:3)

问题是jhipster-uml不支持进化模式。换句话说,一旦jhipster-uml生成你的应用程序资产和liquibase更改日志,它会忘记它做了什么以及下次运行时它会从头开始生成所有内容 - 这对于大多数工件都很好,但是 NOT for changelogs。

有两种方法可以解决这个问题:

  • 在重新运行jhipster

    之前删除更改日志
    • 在另一个答案中有详细说明,另外在重新运行应用程序之前删除所有现有的数据库表。
  • 将jhipster-uml与 liquibase diff

    一起使用
    1. 修改您的UML模型
    2. 导出xmi
    3. 运行jhipster-uml
    4. 还原对更改日志的所有更改,包括master.xml(使用VCS或文件历史记录)
    5. 编译您的Java代码:compileJava
    6. 运行Liquibase diff liquibaseDiffChangelog:这会将您的实体与数据库的当前状态进行比较,并生成实际的更改日志,即包含更改并向master.xml添加记录。
    7. 使用bootRun启动您的应用程序:liquibase任务将执行任何未完成的更改日志

注意:删除和重命名实体时要小心:您必须从前端资产,java类,更改日志,数据库表,.jhipster实体中删除大量孤立文件

答案 2 :(得分:0)

以防任何人遇到这种情况,并使用Gradle。这就是我所做的:

  

第一。检查master.xml文件和那里包含的文件,检查一切是否符合预期。

然后clearChecksums

根据液体基础文件

Removes current checksums from database. On next run checksums will be recomputed.

所以

打开liquidbase.gradle 并添加了以下条目:

task liquibaseClearChecksums(dependsOn: compileJava, type: JavaExec) {
    group = "liquibase"

    classpath sourceSets.main.runtimeClasspath
    classpath configurations.liquibase
    main = "liquibase.integration.commandline.Main"

    args "--changeLogFile=src/main/resources/config/liquibase/changelog/" + buildTimestamp() +"_changelog.xml"
    args "--referenceUrl=hibernate:spring:com.asimplemodule.deptmanager.domain?dialect=com.asimplemodule.deptmanager.domain.util.FixedPostgreSQL82Dialect&hibernate.ejb.naming_strategy=org.springframework.boot.orm.jpa.hibernate.SpringNamingStrategy"
    args "--username=mycoolapp"
    args "--password=mycoolapp"
    args "--url=jdbc:postgresql://localhost:5432/mycoolApp"
    args "--driver=org.postgresql.Driver"
    args "clearChecksums"

}

然后只需运行gradle liquibaseClearChecksums

这解决了我的问题。

希望它有助于某人