问题
I have a modelio UML class model. I have been updating it all the time and after that I run jhipster-uml .xmi to regenerate entities. I always ended up to error messages. I tried to delete from -jhipster files the entity.json files but it doesn't help. So could you tell me what is correct workaround to update entities during the development? I tried to run maven:diff task as well, but no luck.
EDIT:
I created a new jhipster app and created entities from modelio UML class model. Everything is working fine. Then I just added one attribute to my model and regenerate the entity from xmi-file and everything os broken again.
My workflow was: 1) save uml model as xmi-file 2) Run jhipster-uml ac2.xmi -paginate 3) Compile my app in intellijIdea 4) run maven task: mvn compile liquibase:diff to create a new changelog 5) run application 6) Watch the error messages:
1 change sets check sum
classpath:config/liquibase/changelog/20150828220237_added_entity_Employee.xml::20150828220237::jhipster is now: 7:dd10f74a01a95b4e48c592e796a1d352
Part of the error:
[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
回答1:
When I want to regenerate all my tables I do this
- Update the model in MODELIO
- Re-export the xmi
rm -rf ./.jhipster/
- Open file
src/main/resources/config/liquibase/master.xml
and remove all<include>
elements exceptconfig/liquibase/changelog/00000000000000_initial_schema.xml
, and- The comment "JHipster will add liquibase changelogs here"
- Sometimes I have to delete lines (except the first having
ID ='00000000000001'
) from tableDATABASECHANGELOG
- Re-run
jhipster-uml
回答2:
The problem is that jhipster-uml doesn't support evolving a schema. In other words, once jhipster-uml generates your application assets and liquibase changelogs, it forgets what it did and when it runs the next time, it generates everything from scratch - that's fine for most of the artifacts, but NOT for the changelogs.
There are two ways to solve this:
Remove the changelogs before re-running jhipster
- detailed in another answer, in addition drop all existing DB tables before re-running your application.
Use jhipster-uml with liquibase diff
- Modify your UML model
- Export the xmi
- Run
jhipster-uml
- Revert all changes to the changelogs including master.xml (using VCS or file history)
- Compile your Java code:
compileJava
- Run Liquibase diff
liquibaseDiffChangelog
: this compares your entities with the current state of the database and generates an actual changelog, i.e. containing changes and adds a record to master.xml. - Launch your application with
bootRun
: the liquibase task will execute any outstanding changelogs
Note: be careful when deleting and renaming entities: you'll have to go and remove a number of orphaned files from front-end assets, java classes, changelogs, db tables, .jhipster entities.
回答3:
Just in case anybody encounters this situation, and is using Gradle. This is what I did :
1st. Check master.xml file and files included there to check everything is as expected.
Then clearChecksums
.
according to the liquidbase documentation
it Removes current checksums from database. On next run checksums will be recomputed.
So
Open liquidbase.gradle And added the folowwing entry :
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"
}
Then just run gradle liquibaseClearChecksums
And that fixed my problem.
Hope it helps someone
来源:https://stackoverflow.com/questions/32278065/what-is-correct-workaround-when-updating-entities-in-jhipster