在 jhipster 中更新实体时正确的解决方法是什么?
What is correct workaround when updating entities in jhipster?
我有一个 modelio UML class 模型。我一直在更新它,之后我 运行 jhipster-uml .xmi 重新生成实体。我总是以错误消息告终。我试图从 -jhipster 文件中删除 entity.json 文件,但没有帮助。那么您能告诉我在开发过程中更新实体的正确解决方法是什么吗?我也尝试 运行 maven:diff 任务,但没有成功。
编辑:
我创建了一个新的 jhipster 应用程序并从 modelio UML class 模型创建了实体。一切正常。然后,我向我的模型添加了一个属性,并从 xmi 文件中重新生成了实体,所有内容 os 再次损坏。
我的工作流程是:
1) 将 uml 模型保存为 xmi 文件
2) 运行 jhipster-uml ac2.xmi -分页
3)在intellijIdea中编译我的应用程序
4) 运行 maven 任务:mvn compile liquibase:diff 创建一个新的变更日志
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.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
当我想重新生成所有 table 时,我会这样做
- 更新MODELIO中的模型
- 重新导出 xmi
rm -rf ./.jhipster/
- 打开文件
src/main/resources/config/liquibase/master.xml
并删除所有 <include>
元素,除了
config/liquibase/changelog/00000000000000_initial_schema.xml
,以及
- 评论"JHipster will add liquibase changelogs here"
- 有时我必须从 table
DATABASECHANGELOG
中删除行(除了第一行 ID ='00000000000001'
)
- 重新运行
jhipster-uml
问题是 jhipster-uml 不支持发展模式。换句话说,一旦 jhipster-uml 生成了你的应用程序资产和 liquibase 变更日志,它就会忘记它做了什么,当它下次运行时,它会从头开始生成所有东西——这对大多数工件来说都很好,但是 NOT 更新日志。
有两种方法可以解决这个问题:
在重新运行 jhipster
之前删除变更日志
- 在另一个答案中有详细说明,另外在重新运行您的应用程序之前删除所有现有的数据库表。
将 jhipster-uml 与 liquibase diff
结合使用
- 修改您的 UML 模型
- 导出 xmi
- 运行
jhipster-uml
- 还原所有更改到更改日志,包括 master.xml(使用 VCS 或文件历史记录)
- 编译您的 Java 代码:
compileJava
- 运行 Liquibase diff
liquibaseDiffChangelog
:这会将您的实体与数据库的当前状态进行比较,并生成实际的更新日志,即包含更改并向 master.xml 添加记录。
- 使用
bootRun
启动您的应用程序:liquibase 任务将执行任何未完成的变更日志
注意:删除和重命名实体时要小心:您必须从前端资产中删除一些孤立文件,java 类、变更日志、数据库表、.jhipster 实体。
以防万一有人遇到这种情况,正在使用Gradle。这就是我所做的:
1st. Check master.xml file and files included there to check everything is as expected.
然后 clearChecksums
.
根据 liquidbase 文档
它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
这解决了我的问题。
希望对大家有所帮助
我有一个 modelio UML class 模型。我一直在更新它,之后我 运行 jhipster-uml .xmi 重新生成实体。我总是以错误消息告终。我试图从 -jhipster 文件中删除 entity.json 文件,但没有帮助。那么您能告诉我在开发过程中更新实体的正确解决方法是什么吗?我也尝试 运行 maven:diff 任务,但没有成功。
编辑:
我创建了一个新的 jhipster 应用程序并从 modelio UML class 模型创建了实体。一切正常。然后,我向我的模型添加了一个属性,并从 xmi 文件中重新生成了实体,所有内容 os 再次损坏。
我的工作流程是: 1) 将 uml 模型保存为 xmi 文件 2) 运行 jhipster-uml ac2.xmi -分页 3)在intellijIdea中编译我的应用程序 4) 运行 maven 任务:mvn compile liquibase:diff 创建一个新的变更日志 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.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
当我想重新生成所有 table 时,我会这样做
- 更新MODELIO中的模型
- 重新导出 xmi
rm -rf ./.jhipster/
- 打开文件
src/main/resources/config/liquibase/master.xml
并删除所有<include>
元素,除了config/liquibase/changelog/00000000000000_initial_schema.xml
,以及- 评论"JHipster will add liquibase changelogs here"
- 有时我必须从 table
DATABASECHANGELOG
中删除行(除了第一行 - 重新运行
jhipster-uml
ID ='00000000000001'
)
问题是 jhipster-uml 不支持发展模式。换句话说,一旦 jhipster-uml 生成了你的应用程序资产和 liquibase 变更日志,它就会忘记它做了什么,当它下次运行时,它会从头开始生成所有东西——这对大多数工件来说都很好,但是 NOT 更新日志。
有两种方法可以解决这个问题:
在重新运行 jhipster
之前删除变更日志- 在另一个答案中有详细说明,另外在重新运行您的应用程序之前删除所有现有的数据库表。
将 jhipster-uml 与 liquibase diff
结合使用- 修改您的 UML 模型
- 导出 xmi
- 运行
jhipster-uml
- 还原所有更改到更改日志,包括 master.xml(使用 VCS 或文件历史记录)
- 编译您的 Java 代码:
compileJava
- 运行 Liquibase diff
liquibaseDiffChangelog
:这会将您的实体与数据库的当前状态进行比较,并生成实际的更新日志,即包含更改并向 master.xml 添加记录。 - 使用
bootRun
启动您的应用程序:liquibase 任务将执行任何未完成的变更日志
注意:删除和重命名实体时要小心:您必须从前端资产中删除一些孤立文件,java 类、变更日志、数据库表、.jhipster 实体。
以防万一有人遇到这种情况,正在使用Gradle。这就是我所做的:
1st. Check master.xml file and files included there to check everything is as expected.
然后 clearChecksums
.
根据 liquidbase 文档
它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
这解决了我的问题。
希望对大家有所帮助