Springframework.dao.InvalidDataAccessResourceUsageException hibernate.SQLGrammarException MySQLSyntaxErrorException

时间:2016-04-20 18:47:22

标签: java mysql spring hibernate persistence

我试图弄清楚这里有什么问题。我正在制作一个模式:它有一个故事实体(表格:故事),我试图在此 stories.portofoliotype_id 中添加一列这是 PortfolioType(表:portofoliotypes)的外键。我认为我有正确的注释,我甚至记录了MySQL查询,它得到以下查询,这是正确的。我试图创造一个新故事: insert into stories(backlog_id, description, iteration_id, name, parent_id,portfoliotype_id, state, storyPoints, storyValue, treeRank) values (11, null, null, 'debug story', null, null, 0, null, null, 0)

但是hibernate失败并出现上述异常。这是代码:

Story.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());
}

StoryDAOImpl.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 个答案:

答案 0 :(得分:8)

错误基本上是说PortfolioType上没有可以找到portfoliotype_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 **/
}

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

此外,只是提示,将这些注释放在制定者身上,这使得阅读和理解你的人际关系变得更加困难。通常的惯例是将这些注释放在字段声明中。

答案 1 :(得分:0)

当数据库访问限制为只读模式并且您尝试执行任何DML查询时,通常会抛出InvalidDataAccessResourceUsageException