0

I'm not sure how to fix the below exception. My datasource is injected into the sessionfactory and used by the DAO to create queries. My database is working perfectly fine considering other modules of the application are working fine. This makes me suspect that my model class 'Shopping' is wrong in some way. Is using java.sql.blob the incorrect way to represent a long blob in mysql database?

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

Model class:

@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 method:

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

complete stack trace:

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)

I would greatly appreciate any help

4
  • Please add the complete stacktrace Commented Mar 2, 2017 at 14:32
  • added stack trace Commented Mar 2, 2017 at 16:40
  • The first part is truncated after toy. the last part starts at 'at ...'. So we're still missing the crucial part of the stack trace. Commented Mar 2, 2017 at 16:50
  • updated stack trace Commented Mar 3, 2017 at 18:39

1 Answer 1

1

Turns out the error was being cause by an incorrect date in the mySQL table, I did not format dates correctly.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.