我有问题;因为我无法在我正在做的roo项目中获得结果,所以我决定重新开始一个教程。一切顺利,直到我试图删除数据库中的项目(与数据库中的其他项目相关)。(尽管Spring Roo实体已在所有级联中配置)
URL TUTORIAL:http://docs.spring.io/spring-roo/reference/html/beginning.html(直到2.9(步骤6))
它给了我以下错误:
异常消息
org.hibernate.exception.ConstraintViolationException: could not execute statement;
nested exception is javax.persistence.PersistenceException:
org.hibernate.exception.ConstraintViolationException: could not execute statement
异常堆栈跟踪
org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:321)
org.springframework.orm.jpa.DefaultJpaDialect.translateExceptionIfPossible(DefaultJpaDialect.java:121)
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755)
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724)
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:475)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:270)
org.springframework.transaction.aspectj.AbstractTransactionAspect.ajc$around$org_springframework_transaction_aspectj_AbstractTransactionAspect$1$2a73e96c(AbstractTransactionAspect.aj:63)
com.project.domain.Base_Roo_Jpa_ActiveRecord.ajc$interMethod$com_project_domain_Base_Roo_Jpa_ActiveRecord$com_project_domain_Base$remove(Base_Roo_Jpa_ActiveRecord.aj:71)
com.project.domain.Base.remove(Base.java:1)
com.project.domain.Base_Roo_Jpa_ActiveRecord.ajc$interMethodDispatch1$com_project_domain_Base_Roo_Jpa_ActiveRecord$com_project_domain_Base$remove(Base_Roo_Jpa_ActiveRecord.aj)
com.project.web.BaseController_Roo_Controller.ajc$interMethod$com_project_web_BaseController_Roo_Controller$com_project_web_BaseController$delete(BaseController_Roo_Controller.aj:80)
com.project.web.BaseController.delete(BaseController.java:1)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
org.springframework.web.servlet.FrameworkServlet.doDelete(FrameworkServlet.java:860)
javax.servlet.http.HttpServlet.service(HttpServlet.java:653)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:74)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:744)
这是数据库:http://docs.spring.io/spring-roo/reference/html/images/pizza.png
所以即使使用sql或phpmyadmin网站我也无法删除。 如果有人能帮助我,我将非常感激。
LOG.ROO
// Spring Roo 1.2.5.RELEASE [rev 8341dc2] log opened at 2014-02-21 11:31:40
project --topLevelPackage com.project --projectName PizzaProject --java 7 --packaging WAR
// Spring Roo 1.2.5.RELEASE [rev 8341dc2] log closed at 2014-02-21 11:31:59
// Spring Roo 1.2.5.RELEASE [rev 8341dc2] log opened at 2014-02-21 11:32:07
hint
jpa setup --provider HIBERNATE --database MYSQL --databaseName springroo
entity jpa --class ~.domain.Topping --testAutomatically
field string --fieldName name --notNull --sizeMin 2
entity jpa --class ~.domain.Base --testAutomatically
field string --fieldName name --notNull --sizeMin 2
entity jpa --class ~.domain.Pizza --testAutomatically
field string --fieldName name --notNull --sizeMin 2
field number --fieldName price --type java.lang.Float
field set --fieldName toppings --type ~.domain.Topping
field reference --fieldName base --type ~.domain.Base
entity jpa --class ~.domain.PizzaOrder --testAutomatically
field string --fieldName name --notNull --sizeMin 2
field string --fieldName address --notNull --sizeMax 30
field number --fieldName total --type java.lang.Float
field date --fieldName deliveryDate --type java.util.Date
field set --fieldName pizzas --type ~.domain.Pizza
perform test
web mvc setup
web mvc all --package ~.web
// Spring Roo 1.2.5.RELEASE [rev 8341dc2] log closed at 2014-02-21 11:58:48
我只创建了数据库,并且hibernate / roo表。 Hibernate设置为hibernate.hbm2ddl.auto。但后来我改为更新以保留记录。
答案 0 :(得分:0)
我猜你试图删除一条从其他表中引用记录的记录。
删除PizzaOrder时,它应该可以正常工作。但是如果您尝试删除Pizza会在PizzaOrder中存在一些数据,则无法执行此操作,因为它未配置为在删除时级联。