org.hibernate.exception.GenericJDBCException:无法根本原因执行查询

时间:2017-03-02 14:31:16

标签: java mysql spring hibernate dao

我不确定如何修复以下异常。我的数据源被注入到sessionfactory中,并由DAO用来创建查询。考虑到应用程序的其他模块工作正常,我的数据库工作正常。这让我怀疑我的模特课“购物”在某种程度上是错误的。使用java.sql.blob是不正确的方式来表示mysql数据库中的长blob?

SEVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [/Online_Shopping] threw exception [Request processing failed; nested exception is org.springframework.orm.hibernate4.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [select this_.Name as Name1_0_0_, this_.Date1 as Date2_0_0_, this_.Date2 as Date3_0_0_, this_.Image as Image4_0_0_, this_.Price as Price5_0_0_ from shopping this_]; SQL state [S1009]; error code [0]; could not execute query; nested exception is org.hibernate.exception.GenericJDBCException: could not execute query] with root cause java.sql.SQLException: Value 'toy

模特课:

@Entity
    @Table(name="shopping")
    public class Shopping implements java.io.Serializable {
        private static final long serialVersionUID = 1L;
            @Id
        @Column(name="Name", unique=true, nullable=false, length=50)
    public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }

        @Column(name="Price", nullable=false, length=50)
        public String getPrice() {
            return price;
        }
        public void setPrice(String price) {
            this.price = price;
        }
        @Temporal(TemporalType.DATE)
        @Column(name="Date1", nullable=false)
        public Date getDate1() {
            return date1;
        }
        public void setDate1(Date date1) {
            this.date1 = date1;
        }
        @Temporal(TemporalType.DATE)
        @Column(name="Date2", nullable=false)
        public Date getDate2() {
            return date2;
        }
        public void setDate2(Date date2) {
            this.date2 = date2;
        }
    private String name;
      private String price;
      private Date date1;
     private Date date2;
     private Blob image;
     @Column(name="Image", nullable=false)
    public Blob getImage() {
        return image;
    }
    public void setImage(Blob image) {
        this.image = image;
    }
    }

DAO方法:

public List<Shopping> getShopping() {
        Session session = sessionFactory.openSession();
        List<Shopping> list = session.createCriteria(Shopping.class).list();
        session.close();
        return list;
    }

完整的堆栈跟踪:

EVERE: Servlet.service() for servlet [mvc-dispatcher] in context with path [/Online_Shopping] threw exception [Request processing failed; nested exception is org.springframework.orm.hibernate4.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [select this_.Name as Name1_0_0_, this_.Date1 as Date2_0_0_, this_.Date2 as Date3_0_0_, this_.Image as Image4_0_0_, this_.Price as Price5_0_0_ from shopping this_]; SQL state [S1009];  q qerror code [0]; could not execute query; nested exception is org.hibernate.exception.GenericJDBCException: could not execute query] with root cause java.sql.SQLException: Value 'toy
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1084)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:987)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:973)
            at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:918)
            at com.mysql.jdbc.ResultSetRow.getDateFast(ResultSetRow.java:141)
            at com.mysql.jdbc.BufferRow.getDateFast(BufferRow.java:707)
            at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2206)
            at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2168)
            at com.mysql.jdbc.ResultSetImpl.getDate(ResultSetImpl.java:2233)
            at org.hibernate.type.descriptor.sql.DateTypeDescriptor$2.doExtract(DateTypeDescriptor.java:67)
            at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
            at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
            at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:261)
            at org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:251)
            at org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:336)
            at org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2924)
            at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1695)
    at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1627)
        at org.hibernate.loader.Loader.getRow(Loader.java:1509)
        at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:719)
        at org.hibernate.loader.Loader.processResultSet(Loader.java:949)
        at org.hibernate.loader.Loader.doQuery(Loader.java:917)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:348)
        at org.hibernate.loader.Loader.doList(Loader.java:2550)
        at org.hibernate.loader.Loader.doList(Loader.java:2536)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2366)
        at org.hibernate.loader.Loader.list(Loader.java:2361)
        at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:124)
        at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1587)
        at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374)
        at com.shopping.dao.UserDaoImpl.getShopping(UserDaoImpl.java:75)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
        at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:85)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
        at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:343)
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:260)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)

我非常感谢任何帮助

1 个答案:

答案 0 :(得分:1)

事实证明错误是由mySQL表中的错误日期引起的,我没有正确格式化日期。