I have this problem: I can write to a Postgis table with a geography type column and the data is entered correctly. When I try to get it back, I get a java.lang.IllegalArgumentException: Can't convert object of type org.postgresql.util.PGobject
I'm using Hibernate Spatial 4.0M1, Postgis 2.0.2, Postgresql 9.1.7 and Spring 3.2, Postgis-jdbc 2.0.2 and I tried also 1.5.2 and Postgresql-jdbc 9.1-901.
This is the relevant part of my class
public class Poi {
#Id
#GeneratedValue(generator="t_pois_poisid_seq")
private long poisid;
#Column(name="name")
private String name;
#Column(name="userid")
private int owner;
//#Column(columnDefinition = "Geometry", name="location")
#Type(type="org.hibernate.spatial.GeometryType")
private Point location;
public Poi(){}
public Poi(String name, int owner, String wktPoint){
this.name = name;
this.owner = owner;
WKTReader fromText = new WKTReader();
Geometry geom = null;
try{
geom = fromText.read(wktPoint);
}catch(ParseException e){
throw new RuntimeException("Not a WKT string:" + wktPoint);
}
if (!geom.getGeometryType().equals("Point")) {
throw new RuntimeException("Geometry must be a point. Got a " + geom.getGeometryType());
}
//geom.setSRID(4326);
this.location = (Point) geom;
}
}
And this is the error I get
java.lang.IllegalArgumentException: Can't convert object of type org.postgresql.util.PGobject
org.hibernate.spatial.dialect.postgis.PGGeometryValueExtractor.toJTS(PGGeometryValueExtractor.java:99)
org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:42)
org.hibernate.spatial.dialect.AbstractJTSGeometryValueExtractor.extract(AbstractJTSGeometryValueExtractor.java:37)
org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:269)
org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:265)
org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:238)
org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:357)
org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2807)
org.hibernate.loader.Loader.loadFromResultSet(Loader.java:1545)
org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:1477)
org.hibernate.loader.Loader.getRow(Loader.java:1377)
org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:644)
org.hibernate.loader.Loader.doQuery(Loader.java:854)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:293)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:263)
org.hibernate.loader.Loader.loadEntity(Loader.java:1977)
org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82)
org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72)
org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3821)
org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:458)
org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:427)
org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:204)
org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:260)
org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:148)
org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1075)
org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:175)
org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2421)
org.hibernate.internal.SessionImpl.get(SessionImpl.java:971)
com.prismio.pois.api.repository.HibernatePoiRepository.findOne(HibernatePoiRepository.java:30)
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:601)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
$Proxy24.findOne(Unknown Source)
com.prismio.pois.api.controller.PoiController.getUser(PoiController.java:40)
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:601)
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:746)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
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:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
If anyone is interested: the problem is that PostGIS returns a PGObject from a column type Geography and not PGGeometry, so the cast to PGgeometry is not possible. The solution I found using jdbcTemplate (and not Hibernate) is to cast the field from the resultset to PGObject and then create a PGGeometry like this:
PGgeometry geo = new PGgeometry(myPGObject.getValue());
Doing this, geo.getValue() returns a string in the form SRID=4326;POINT(40.70686417491799 -74.01572942733765) which is what I wanted. I could do the query using ST_AsText but it loses precision. I don't know Hibernate well enough to propose a solution to this, but this is enough for my use case.
Related
As part of my project requirement I need to pass Collection of objects (List of objects) to oracle stored procedure. And Once I receive the collection object In stored procedure I will do some DB operation using the data. I am getting some issue in java code while setting the argument for stored procedure.
From database side I have created custom type.
create or replace type ESLSolveRequests as Object(latitude Number(38,10),longitude Number(38,10),isExist char(1),rec_id Number,route_cost Number,route_length Number,route_impedance Number);
create or replace type ESLSolveList as table of ESLSolveRequests;
Below are Package and stored procedure
create or replace package PKG_ESL_NSX_Record_Check as
procedure proc_Check_RecordExistance(MAP_IN IN ESLSolveList,MAP_OUT OUT ESLSolveList);
end PKG_ESL_NSX_Record_Check;
create or replace package body PKG_ESL_NSX_Record_Check
as
procedure proc_Check_RecordExistance(MAP_IN IN ESLSolveList,MAP_OUT OUT ESLSolveList)
is
begin
null;
end proc_Check_RecordExistance;
end PKG_ESL_NSX_Record_Check;
Below is java code ,my List List eslSolveRequest is populated with objects, below is my java code
#Repository
public class EslNsxCheckDao extends DatabaseConnection {
private StructDescriptor strDescriptor = null;
private ArrayDescriptor arrayDescriptor = null;
private OracleCallableStatement cStmt = null;
private ARRAY p_message_list = null;
Connection con = null;
public void checkWithNSXDb(List<ESLSolveRequest> eslSolveRequest){
oracle.sql.ARRAY array =null;
try{
Connection con=getJdbcConnection();
this.arrayDescriptor = ArrayDescriptor.createDescriptor("ESLSolveList", con);
this.strDescriptor=StructDescriptor.createDescriptor("ESLSolveRequests",con);
}catch(Exception ex){
}
try {
Object[] param_array=eslSolveRequest.toArray();
p_message_list = new oracle.sql.ARRAY(this.arrayDescriptor, con, param_array);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
this.cStmt =(OracleCallableStatement)conn.prepareCall("{call PKG_ESL_NSX_Record_Check.proc_Check_RecordExistance(:1,:2)}");
this.cStmt.setArray(1, p_message_list);
this.cStmt.registerOutParameter(2,OracleTypes.ARRAY,"ESLSolveList");
this.cStmt.execute();
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
I am getting below error
**java.sql.SQLException: Missing descriptor**
at oracle.sql.DatumWithConnection.assertNotNull(DatumWithConnection.java:103)
at oracle.sql.ARRAY.<init>(ARRAY.java:117)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao.checkWithNSXDb(EslNsxCheckDao.java:37)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao$$FastClassBySpringCGLIB$$b62b799d.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao$$EnhancerBySpringCGLIB$$6c531bd5.checkWithNSXDb(<generated>)
at com.comcast.BulkSolveRecordProcess.Batch.Processor.process(Processor.java:28)
at com.comcast.BulkSolveRecordProcess.Batch.Processor.process(Processor.java:12)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:126)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:293)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:192)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:272)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:392)
at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:135)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
at com.sun.proxy.$Proxy75.run(Unknown Source)
at com.comcast.BulkSolveRecordProcess.Events.ScheduledEvents.trigger(ScheduledEvents.java:76)
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.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
**java.sql.SQLException: Invalid argument(s) in call
at** oracle.jdbc.driver.OraclePreparedStatement.setARRAYInternal(OraclePreparedStatement.java:6405)
at oracle.jdbc.driver.OraclePreparedStatement.setArrayInternal(OraclePreparedStatement.java:6362)
at oracle.jdbc.driver.OracleCallableStatement.setArray(OracleCallableStatement.java:5682)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.setArray(OraclePreparedStatementWrapper.java:121)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao.checkWithNSXDb(EslNsxCheckDao.java:45)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao$$FastClassBySpringCGLIB$$b62b799d.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:738)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:673)
at com.comcast.BulkSolveRecordProcess.DAO.EslNsxCheckDao$$EnhancerBySpringCGLIB$$6c531bd5.checkWithNSXDb(<generated>)
at com.comcast.BulkSolveRecordProcess.Batch.Processor.process(Processor.java:28)
at com.comcast.BulkSolveRecordProcess.Batch.Processor.process(Processor.java:12)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:126)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:293)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:192)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
Hibernate+Spring Boot
i can not get object
My controller
#RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
public #ResponseBody
SuperStudentEntity getById(#PathVariable("id") int id) {
return new StudentDAOImpl().getById(id);
}
DAO function
public SuperStudentEntity getById(int id){
openTransactionSession();
Session s = getSession();
String sql = "SELECT * FROM student WHERE id_student =:id";
org.hibernate.query.Query query = s.createNativeQuery(sql).addEntity(SuperStudentEntity.class);
query.setParameter("id",id);
SuperStudentEntity student = (SuperStudentEntity) query.getSingleResult();
closeTransactionSesstion();
return student;
}
And get exceptions
java.lang.ClassCastException: org.codexample.ent.SuperStudentEntity cannot be cast to org.codexample.ent.SuperStudentEntity
at org.codexample.impldao.StudentDAOImpl.getById(StudentDAOImpl.java:45) ~[classes/:na]
at org.codexample.controllers.StudentController.getById(StudentController.java:54) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133) ~[spring-web-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) ~[spring-webmvc-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at ....
And browser tell me :
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thu May 18 20:02:30 MSK 2017 There was an unexpected error (type=Internal Server Error, status=500). org.codexample.ent.SuperStudentEntity cannot be cast to org.codexample.ent.SuperStudentEntity
I don't understand how resolve it problem.
I have these classes:
public class UserCredential {
#NotNull(message ="The password must not be null !")
#NotEmpty(message="The password must not be empty !")
private String password;
#NotNull(message ="The email/name must not be null !")
#NotEmpty(message="The email/name must not be empty !")
private String email;
//GETTERS AND SETTERS
}
and my real Entity is like this :
#Entity
public class BlogUser {
#Id
#GeneratedValue
private Long id;
private String name;
private String email;
private String password;
private String website;
//GETTERS AND SETTERS
}
I use Spring and In my repository tier I have a method like this :
public boolean isValidLogin(UserCredential userCredential) {
List <BlogUser> list = em.createQuery("SELECT c FROM BlogUser c WHERE c.email = " + userCredential.getEmail()+ " AND c.password = " + userCredential.getPassword()).getResultList();
if (list.size() == 1) {
return true;
} else {
return false;
}
}
but when my program is going to execute the query I get this error:
HTTP Status 500 - Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
type Exception report
message Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1387)
org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1310)
org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:277)
com.sts.repository.UserRepositoryImpl.isValidLogin(UserRepositoryImpl.java:52)
com.sts.service.UserServiceImpl.isValidLogin(UserServiceImpl.java:37)
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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
com.sun.proxy.$Proxy44.isValidLogin(Unknown Source)
com.sts.controller.Welcome.loginUser(Welcome.java:53)
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.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause
org.hibernate.exception.SQLGrammarException: could not extract ResultSet
org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:123)
org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:61)
org.hibernate.loader.Loader.getResultSet(Loader.java:2040)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1837)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1816)
org.hibernate.loader.Loader.doQuery(Loader.java:900)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
org.hibernate.loader.Loader.doList(Loader.java:2526)
org.hibernate.loader.Loader.doList(Loader.java:2512)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2342)
org.hibernate.loader.Loader.list(Loader.java:2337)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:356)
org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
org.hibernate.internal.SessionImpl.list(SessionImpl.java:1269)
org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:268)
com.sts.repository.UserRepositoryImpl.isValidLogin(UserRepositoryImpl.java:52)
com.sts.service.UserServiceImpl.isValidLogin(UserServiceImpl.java:37)
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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
com.sun.proxy.$Proxy44.isValidLogin(Unknown Source)
com.sts.controller.Welcome.loginUser(Welcome.java:53)
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.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
root cause
org.postgresql.util.PSQLException: ERROR: column "mehdi" does not exist
Position: 286
org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2157)
org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1886)
org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:555)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:417)
org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:302)
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:56)
org.hibernate.loader.Loader.getResultSet(Loader.java:2040)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1837)
org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1816)
org.hibernate.loader.Loader.doQuery(Loader.java:900)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)
org.hibernate.loader.Loader.doList(Loader.java:2526)
org.hibernate.loader.Loader.doList(Loader.java:2512)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2342)
org.hibernate.loader.Loader.list(Loader.java:2337)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495)
org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:356)
org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)
org.hibernate.internal.SessionImpl.list(SessionImpl.java:1269)
org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)
org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:268)
com.sts.repository.UserRepositoryImpl.isValidLogin(UserRepositoryImpl.java:52)
com.sts.service.UserServiceImpl.isValidLogin(UserServiceImpl.java:37)
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.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198)
com.sun.proxy.$Proxy44.isValidLogin(Unknown Source)
com.sts.controller.Welcome.loginUser(Welcome.java:53)
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.doPost(FrameworkServlet.java:838)
javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter.doFilterInternal(OpenEntityManagerInViewFilter.java:180)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
This is the my example query trace:
Hibernate:
select
tuser0_.id as id1_1_,
tuser0_.email as email2_1_,
tuser0_.name as name3_1_,
tuser0_.password as password4_1_,
tuser0_.website as website6_1_
from
BlogUser tuser0_
where
tuser0_.email=mehdi
and tuser0_.password=123456
you think, what is the problem ???
When building your query without parameters (it's a bad idea) you need to take care of quote and type convertion etc...
List <BlogUser> list = em.createQuery("SELECT c FROM BlogUser c WHERE c.email = '" + userCredential.getEmail()+ "' AND c.password = '" + userCredential.getPassword()+"'").getResultList();
A better solution is to use parameters :
List <BlogUser> list = em.createQuery("SELECT c FROM BlogUser c WHERE c.email = :email AND c.password = :pwd")
.setParameter("email",userCredential.getEmail())
.setParameter("pwd",userCredential.getPassword())
.getResultList();
Like ben75's answer, it is preferred to use parameters instead of modifying the query String.
The other problem is that you may be trying to get a list of BlogUser just to count them. Imagine that the BlogUser has a eager list of attributes. You may end up doing many SELECTS just to see if there is any BlogUser with the desired email/password.
It is better if you delegate the counting part to the database.
public boolean isValidLogin(UserCredential userCredential) {
Integer count = (Integer)em.createQuery(
"SELECT count(c.id) "+
"FROM BlogUser c " +
"WHERE c.email = :email AND c.password = :pwd")
.setParameter("email",userCredential.getEmail())
.setParameter("pwd",userCredential.getPassword())
.getSingleResult();
if (count == 1) {
return true;
} else {
return false;
}
}
I would like to get the id of the currently logged in user and use it to access their specific user page.
To implement that I have been able to get the current logged in user's name using:
#RequestMapping(value = "/main/home", method = RequestMethod.GET)
public String getHomePage(Model model, Principal principal, HttpServletRequest
request) {
try {
CustomUser customUser =
(CustomUser)SecurityContextHolder.getContext()
.getAuthentication().getPrincipal();
request.getSession().setAttribute("name",
customUser.getName());
request.getSession().setAttribute("userId",
customUser.getUserId());
request.getSession().setAttribute("user", customUser);
} catch (Exception e) {
e.printStackTrace();
}
return "/main/home";
}
Then in the JSP page, I'm using the following code to try to get the user's page based on their id:
<c:url value="/main/user/?userId=${user.userId}" var="url"/><a href="<c:out
value='${url}'/>">User Page</a>
But this implementation is not working. When I click on the user page, I receive the following error:
java.lang.IllegalArgumentException: id to load is required for loading
org.hibernate.event.spi.LoadEvent.<init>(LoadEvent.java:87)
org.hibernate.event.spi.LoadEvent.<init>(LoadEvent.java:59)
org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2421)
org.hibernate.internal.SessionImpl.get(SessionImpl.java:974)
com.project.myapp.dao.UserDAO.getUserByID(UserDAO.java:91)
com.project.myapp.dao.UserDAO$$FastClassByCGLIB$$b394c410.invoke(<generated>)
org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
com.project.myapp.dao.UserDAO$$EnhancerByCGLIB$$232ac7e1.getUserByID(<generated>)
com.project.myapp.service.UserServiceImpl.getUserByID(UserServiceImpl.java:54)
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:601)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
$Proxy314.getUserByID(Unknown Source)
com.project.myapp.controller.UserController.getUserPage(UserController.java:70)
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:601)
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:746)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687)
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:915)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:811)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
I would like any insight into knowing why I cannot request the user's id but I can get the user's name.
I am new to Spring MVC and Hibernate and am learning along the way.
I encountered this problem when I was trying to upload images onto the site and store it in MySQL database.
I have a project model, which consists of a list of photo model. In each photo model, there is a field (CommonsMultipartFile) called photo that actually stores the photo.
ProjectModel.java
public class ProjectModel{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
#OneToMany(fetch = FetchType.LAZY, cascade=CascadeType.ALL)
private List<PhotoModel> photos;
//getters and setters
}
PhotoModel.java
public class PhotoModel extends AbstractModel implements Serializable{
#Id
#GeneratedValue(strategy = GenerationType.AUTO)
private int id;
#Column(columnDefinition = "LONGBLOB")
private CommonsMultipartFile photo;
#ManyToOne(fetch = FetchType.LAZY)
private ProjectModel project;
//getters and setters
}
addProject.jsp
<form:input type="file" path="photos[0].photo"/>
<form:input type="file" path="photos[1].photo"/>
ProjectController.java
#RequestMapping(value="/project/add", method = {RequestMethod.GET})
public String toAddProject (Model model){
if (!model.containsAttribute(Constants.COMMAND)){
ProjectModel project = new ProjectModel();
project.setPhotos(new AutoPopulatingList<PhotoModel>(PhotoModel.class));
model.addAttribute(Constants.COMMAND, project);
}
return "/user/addProject";
}
#RequestMapping(value="/project/add", method = {RequestMethod.POST})
public String addProject Model model, #ModelAttribute("command") #Valid ProjectModel command, BindingResult result){
if(result.hasErrors()) {
model.addAttribute(Constants.COMMAND, command);
return toAddProject(model);
}
projectService.save(command);
return "redirect:/success";
}
My problem is that I am able to upload images of certain types, such as jpg or jpeg, but not png. If I try to upload such file, the error is as follows.
org.springframework.orm.hibernate4.HibernateSystemException: could not deserialize; nested exception is org.hibernate.type.SerializationException: could not deserialize
at org.springframework.orm.hibernate4.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:206)
at org.springframework.orm.hibernate4.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:606)
at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:488)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:754)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:723)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:393)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:120)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
at $Proxy32.save(Unknown Source)
at cn.javass.demo.web.controller.ProjectController.addProject(ProjectController.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:213)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at cn.javass.common.web.filter.BackURLFilter.doFilter(BackURLFilter.java:37)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Caused by: org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:250)
at org.hibernate.internal.util.SerializationHelper.deserialize(SerializationHelper.java:306)
at org.hibernate.internal.util.SerializationHelper.clone(SerializationHelper.java:95)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor$SerializableMutabilityPlan.deepCopyNotNull(SerializableTypeDescriptor.java:55)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor$SerializableMutabilityPlan.deepCopyNotNull(SerializableTypeDescriptor.java:42)
at org.hibernate.type.descriptor.java.MutableMutabilityPlan.deepCopy(MutableMutabilityPlan.java:57)
at org.hibernate.type.AbstractStandardBasicType.deepCopy(AbstractStandardBasicType.java:340)
at org.hibernate.type.AbstractStandardBasicType.deepCopy(AbstractStandardBasicType.java:336)
at org.hibernate.type.TypeHelper.deepCopy(TypeHelper.java:67)
at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:135)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:362)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:354)
at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:276)
at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:326)
at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:52)
at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1127)
at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:325)
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:175)
at org.springframework.orm.hibernate4.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:480)
... 53 more
Caused by: java.io.FileNotFoundException: /Users/Paddy/Documents/apache-tomcat-7.0.25/work/Catalina/localhost/Spring3Hibernate4Chinese/upload_1bc5d431_136acd506da__8000_00000013.tmp (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:120)
at org.apache.commons.fileupload.disk.DiskFileItem.readObject(DiskFileItem.java:709)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:969)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1848)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1946)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1870)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1752)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:350)
at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:244)
... 72 more
It seems that a temporary file cannot be found. I am not sure what is really happening behind the scenes by Spring or Hibernate.
Really hope someone could shed some lights on this issue?
Thanks.
After experimenting with this issue for a while, it seems that it does not depend on the type of file I submit but rather the size of the file. If it exceeds a threshold, the problem described occurs.
Since I am not able to tackle this issue, I tried to convert field type from CommonsMultipartFile to byte[] and add an initBinder method at my controller as suggested by this link.
It works.