当前位置: 首页 > 知识库问答 >
问题:

Springframework.dao.InvalidDataAccessResourceUsageExc0019Hibernate。SQL语法异常

弘思聪
2023-03-14

我正打破我的头试图找出这里出了什么问题。我正在研究一个模式:它有一个故事实体(表:故事),我试图向这个stories.portofoliotype添加一个列_id它是PortfolioType的外键(表:portofolitype)。我想我有正确的注释,我甚至记录了MySQL查询,它得到了以下查询,这是正确的。我试图创建一个新的故事:插入到故事(backlog_id,描述,iteration_id,名称,parent_id,portfoliotype_id,状态,故事点,故事值,TreeRank)值(11,空,空,调试故事,空,空,0,空,空,0)

但hibernate失败,出现上述异常。代码如下:

故事JAVA

@Entity
@Table(name = "stories")
@Audited
@XmlRootElement
@XmlAccessorType( XmlAccessType.NONE )
public class Story implements TimesheetLoggable, LabelContainer,     NamedObject, TaskContainer {
private int id;
private String name;
private PortfolioType portfoliotype;
private String description;
private Backlog backlog;
private StoryState state = StoryState.NOT_STARTED;
private int treeRank = 0;
private Story parent;
private Iteration iteration;
private List<Story> children = new ArrayList<Story>();
private Set<Label> labels = new HashSet<Label>();
private Set<User> responsibles = new HashSet<User>();
private Set<Task> tasks = new HashSet<Task>();
private Set<StoryHourEntry> hourEntries = new HashSet<StoryHourEntry>();
private Set<StoryRank> storyRanks = new HashSet<StoryRank>();
private Set<StoryAccess> storyAccesses;
private Set<WhatsNextStoryEntry> whatsNextStoryEntries = new     HashSet<WhatsNextStoryEntry>();
private Integer storyPoints;
private Integer storyValue;
private Story fullInfoStory;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@XmlAttribute(name = "objectId")
public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

@Column(nullable = false)
@XmlAttribute
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

@ManyToOne(optional = true, targetEntity=PortfolioType.class)
@JoinColumn(name="portfoliotype_id")
public PortfolioType getPortfoliotype() {
    return portfoliotype;
}

public void setPortfoliotype(PortfolioType portfolio) {
    this.portfoliotype = portfolio;
}

PortfolioType。JAVA

@Entity
@Table(name="portfoliotypes")
@Audited
@XmlRootElement
@XmlAccessorType( XmlAccessType.NONE )
public class PortfolioType {
public PortfolioType() {}

private int id;
private String name;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@XmlAttribute(name = "objectId")
@Column(name="id")
public int getId() {
    return id;
}

public void setId(int portfoliotype_id) {
    this.id = portfoliotype_id;
}

@Column(nullable=false)
@XmlAttribute
public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

}

和堆栈跟踪:

12:30:09.681 [http-bio-9090-exec-5] ERROR o.a.struts2.dispatcher.Dispatcher - Exception occurred during processing request: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
    org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:130) ~[spring-orm-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.orm.hibernate4.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:682) ~[spring-orm-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:564) ~[spring-orm-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:755) ~[spring-tx-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:724) ~[spring-tx-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:475) ~[spring-tx-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:270) ~[spring-tx-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) ~[spring-tx-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) ~[spring-aop-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at com.sun.proxy.$Proxy74.create(Unknown Source) ~[na:na]
        at fi.hut.soberit.agilefant.web.StoryAction.create(StoryAction.java:92) ~[classes/:na]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_79]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_79]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_79]
        at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_79]
        at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:450) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:289) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:252) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) ~[struts2-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at fi.hut.soberit.agilefant.web.SettingsInterceptor.intercept(SettingsInterceptor.java:23) ~[classes/:na]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at fi.hut.soberit.agilefant.web.SecurityInterceptor.intercept(SecurityInterceptor.java:198) ~[classes/:na]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at fi.hut.soberit.agilefant.web.RefreshUserInterceptor.intercept(RefreshUserInterceptor.java:41) ~[classes/:na]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:256) ~[struts2-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:176) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) ~[struts2-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73) ~[struts2-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91) ~[struts2-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252) ~[struts2-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164) ~[struts2-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246) ~[xwork-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54) ~[struts2-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:546) ~[struts2-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) [struts2-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91) [struts2-core-2.3.14.2.jar:2.3.14.2]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.67]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.67]
        at fi.hut.soberit.agilefant.security.RestrictActionPathFilter.doFilter(RestrictActionPathFilter.java:28) [classes/:na]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.67]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.67]
        at org.springframework.orm.hibernate4.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:149) [spring-orm-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106) [spring-web-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.67]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.67]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at fi.hut.soberit.agilefant.security.SetupUserFilter.doFilter(SetupUserFilter.java:43) [classes/:na]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) [spring-security-web-3.2.5.RELEASE.jar:3.2.5.RELEASE]
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343) [spring-web-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260) [spring-web-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.67]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.67]
        at net.sf.ehcache.constructs.web.filter.GzipFilter.doFilter(GzipFilter.java:95) [ehcache-web-2.0.4.jar:na]
        at net.sf.ehcache.constructs.web.filter.Filter.doFilter(Filter.java:86) [ehcache-web-2.0.4.jar:na]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.67]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.67]
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88) [spring-web-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106) [spring-web-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343) [spring-web-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260) [spring-web-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) [catalina.jar:7.0.67]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [catalina.jar:7.0.67]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) [catalina.jar:7.0.67]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) [catalina.jar:7.0.67]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505) [catalina.jar:7.0.67]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169) [catalina.jar:7.0.67]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) [catalina.jar:7.0.67]
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956) [catalina.jar:7.0.67]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) [catalina.jar:7.0.67]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423) [catalina.jar:7.0.67]
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079) [tomcat-coyote.jar:7.0.67]
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625) [tomcat-coyote.jar:7.0.67]
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318) [tomcat-coyote.jar:7.0.67]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_79]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_79]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-coyote.jar:7.0.67]
        at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79]
    Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:124) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:189) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:59) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3079) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3521) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:88) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:395) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:387) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:303) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:349) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1195) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.envers.synchronization.AuditProcess.doBeforeTransactionCompletion(AuditProcess.java:158) ~[hibernate-envers-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.envers.synchronization.AuditProcessManager$1.doBeforeTransactionCompletion(AuditProcessManager.java:62) ~[hibernate-envers-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.engine.spi.ActionQueue$BeforeTransactionCompletionProcessQueue.beforeTransactionCompletion(ActionQueue.java:748) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.engine.spi.ActionQueue.beforeTransactionCompletion(ActionQueue.java:338) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:490) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:105) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:556) ~[spring-orm-3.2.13.RELEASE.jar:3.2.13.RELEASE]
        ... 130 common frames omitted
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'portfoliotype_id' in 'field list'
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.7.0_79]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) ~[na:1.7.0_79]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.7.0_79]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:526) ~[na:1.7.0_79]
        at com.mysql.jdbc.Util.handleNewInstance(Util.java:411) ~[mysql-connector-java-5.1.23.jar:na]
        at com.mysql.jdbc.Util.getInstance(Util.java:386) ~[mysql-connector-java-5.1.23.jar:na]
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053) ~[mysql-connector-java-5.1.23.jar:na]
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4120) ~[mysql-connector-java-5.1.23.jar:na]
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052) ~[mysql-connector-java-5.1.23.jar:na]
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503) ~[mysql-connector-java-5.1.23.jar:na]
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664) ~[mysql-connector-java-5.1.23.jar:na]
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2794) ~[mysql-connector-java-5.1.23.jar:na]
        at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155) ~[mysql-connector-java-5.1.23.jar:na]
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458) ~[mysql-connector-java-5.1.23.jar:na]
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375) ~[mysql-connector-java-5.1.23.jar:na]
        at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359) ~[mysql-connector-java-5.1.23.jar:na]
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) ~[commons-dbcp-1.4.jar:1.4]
        at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105) ~[commons-dbcp-1.4.jar:1.4]
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:186) ~[hibernate-core-4.2.18.Final.jar:4.2.18.Final]
        ... 148 common frames omitted

非常感谢您的帮助,提前谢谢您。此外,这个测试用例也可以工作:这个测试用例可以工作,即从故事中获取行

@Test
public void testSearchByPortfolioType() {
    int searchfolio = 1;
    String name = "parity";
    PortfolioType portfolio = new PortfolioType();
    portfolio.setId(searchfolio);
    portfolio.setName(name);
    executeClassSql();
    List<Story> stories = storyDAO.searchByPortfolioType(portfolio);
    assertEquals(4, stories.size());
}

故事。JAVA

public List<Story> searchByPortfolioType(PortfolioType portfolio) {
    Criteria crit = this.createCriteria(Story.class);
    Criterion folioCrit = Restrictions.eq("portfoliotype.id",portfolio.getId());
    crit.add(folioCrit);
    crit.addOrder(Order.asc("name"));
    crit.setMaxResults(SearchBusiness.MAX_RESULTS_PER_TYPE);
    return asList(crit);
}

共有2个答案

巫马玉堂
2023-03-14

当数据库访问被限制为只读模式并且您试图执行任何DML查询时,最常见的InvalidDataAccessResourceUsageExc0019会引发。

陈斌蔚
2023-03-14

错误基本上是说,PortfolioType上没有一个名为PortfolioType\u id的字段/列可以找到,因为该字段实际上被称为id

这是一个基本错误,因为您的ID列名与您在@JoinColumn注释中指定的不匹配。

将类更改为以下内容,它应该可以工作。

public class Story implements TimesheetLoggable, LabelContainer, NamedObject, TaskContainer {
    /** other fields omitted for space **/

    @ManyToOne(optional = true, targetEntity=PortfolioType.class)
    @JoinColumn(name="portfolioTypeId")
    private PortfolioType portfoliotype;
}

投资组合类型:

public class PortfolioType {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @XmlAttribute(name = "objectId")
    @Column(name="portfolioTypeId")
    private int portfolioTypeId;

    /** other fields omitted for space **/
}

您需要确保您的@Coliv注释中的name值与您的@JoinColiv注释中的name匹配。这就是为什么总是使用id作为您的ID字段名称不是一个好主意。

此外,仅仅是一个提示,把这些注释放在设置器上,就很难阅读和弄清楚你的关系是什么。通常的惯例是将这些注释放在字段声明上。

 类似资料:
  • 问题内容: 我正在尝试为H2导入一个SQL脚本。该脚本由spring- batch提供,用于存储作业元数据。当我直接在H2控制台中执行此脚本时,没有语法错误,但是我在初始化阶段引用了Hibernate / JPA中要导入的相同脚本,却遇到了以下异常: 这是我要执行的脚本:https : //code.google.com/p/joshlong- examples/source/browse/tru

  • 主要内容:常用 SQL 命令使用 SQL 语言必须遵守一套特定的规范和准则,这称之为 语法(Syntax)。本教程列出了常用的 SQL 语法,以帮助您快速入门 SQL。 所有的 SQL 语法都必须以关键字(也称命令)开头,比如 SELECT、INSERT、UPDATE、DELETE、ALTER、DROP、CREATE、USE、SHOW 等。 所有的 SQL 语句必须以分号 结尾。SQL 语句可以跨行,您可以将 SQL 语句书

  • 数据库表 一个数据库通常包含一个或多个表。每个表由一个名字标识(例如:"Websites"),表包含带有数据的记录(行)。 在本教程中,我们在 MySQL 的 RUNOOB 数据库中创建了 Websites 表,用于存储网站记录。 我们可以通过以下命令查看 "Websites" 表的数据: mysql> use RUNOOB; Database changed mysql> set names

  • S tructured Q uery L anguage(SQL)是一种标准化语言,允许您对数据库执行操作,例如创建条目,读取内容,更新内容和删除条目。 几乎所有您可能使用的数据库都支持SQL,它允许您独立于底层数据库编写数据库代码。 本章概述了SQL,它是理解JDBC概念的先决条件。 完成本章后,您将能够从数据库中创建,创建,重写,使用U pdte和D elete(通常称为CRUD操作)数据。

  • 我是第一个 org.springframework.jdbc.BadSqlGrammarException:准备状态回调;错误的SQL语法[选择cid,临床医生代码,密码,名字,临床医生的姓氏,其中临床医生代码= ?]; 嵌套异常com.mysql.jdbc.exceptions.jdbc4. MySQLSyntaErrorException:字段列表中的未知列“临床医生” 以下代码出错,您还可以

  • 结构化查询语言(SQL)是一种标准化语言,允许对数据库执行操作,例如:创建数据记录,读取内容,更新内容和删除数据记录等。 本教程中将概述SQL,这是了解和学习JDBC概念的前提条件。 经过本章后,您将能够在数据库中创建,创建,读取,更新和删除(通常称为CRUD操作)数据。 有关SQL的详细了解,可以阅读我们的MySQL教程 。 1. 创建数据库 语句用于创建新的数据库。 语法是 - 示例 以下SQ