当前位置:编程学习 > JAVA >>

Hibernate存向数据库存入文件,大小翻倍

想要存储一个3.35M(3522035)的文件到数据库,使用hibernate,数据库配置最大存储限制为4M.
我在我程序blobDao.save(applicationVersion.getContent());这一句前打印输出System.out.print(applicationVersion.getContent().getContentFile().length);的值还是3522035,但是执行save过程中就抛错了:
org.hibernate.exception.GenericJDBCException: Packet for query is too large (7044201 > 4194304). 
文件大小差不多被翻倍了,有人知道这是为什么吗? Hibernate 数据库 --------------------编程问答-------------------- 大小翻翻,很明显是大小叠加了两次,你仔细检查一下,看错误出在哪里。。。不贴代码,别人怎么能才来你的错误。 --------------------编程问答-------------------- 这种帖子以后就不要发了,没代码你问什么啊? --------------------编程问答-------------------- AppVersionService.java中
public void saveAppVersion(MApplicationVersion applicationVersion) {
if (!StringUtils.isEmpty(applicationVersion.getApkTempFilePath())) {
File apkFile = new File(applicationVersion.getApkTempFilePath());
if (apkFile != null && apkFile.exists()) {
try {
applicationVersion.getContent().setContent(apkFile);
} catch (FileNotFoundException e) {
                    logger.error("save application error", e);
} catch (IOException e) {
                    logger.error("save application error", e);
} finally {
apkFile.delete();
}
}
}
        System.out.println(applicationVersion.getContent().getContentFile().length);//这里打印出来的还是实际大小
blobDao.save(applicationVersion.getContent());
applicationVersion.setFileName(applicationVersion.getContent().getContentFileName());
applicationVersion.setApplication(appApplicationDao.get(applicationVersion.getApplicationId()));
appVersionDao.save(applicationVersion);
}


blobDao.save(applicationVersion.getContent());调用我自己写的SimpleHibernateDao.java中的
/**
     * 保存新增或修改的对象.
     */
    public void save(final T entity) {

        Assert.notNull(entity, "entity不能为空");
        getSession().saveOrUpdate(entity);
        logger.debug("save entity: {}", entity);
    }

getSession().saveOrUpdate(entity);进入hibernate-core-4.1.9.Final.jar包,应该没我事了...

单步调试的话,exception最先被AbstractAspectJAdvice.class中的
protected Object invokeAdviceMethodWithGivenArgs(Object[] args) throws Throwable {
Object[] actualArgs = args;
if (this.aspectJAdviceMethod.getParameterTypes().length == 0) {
actualArgs = null;
}
try {
ReflectionUtils.makeAccessible(this.aspectJAdviceMethod);
// TODO AopUtils.invokeJoinpointUsingReflection
return this.aspectJAdviceMethod.invoke(this.aspectInstanceFactory.getAspectInstance(), actualArgs);
}
catch (IllegalArgumentException ex) {
throw new AopInvocationException("Mismatch on arguments to advice method [" +
this.aspectJAdviceMethod + "]; pointcut expression [" +
this.pointcut.getPointcutExpression() + "]", ex);
}
catch (InvocationTargetException ex) {
throw ex.getTargetException();//这里捕获
}
}
--------------------编程问答-------------------- 走下去报错(3522035)就是我的打印值
3522035
2013/08/06 18:50:50,078 DEBUG [http-8080-1] permission throw exception. com.wizarpos.tms.aop.permission.PermissionAspect.permissionThrowing(PermissionAspect.java:83) 
org.hibernate.exception.GenericJDBCException: Packet for query is too large (7044201 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable.
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:54)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at com.sun.proxy.$Proxy108.executeUpdate(Unknown Source)
...
at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:727)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:719)
at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:715)
at com.wizarpos.tms.common.orm.hibernate.SimpleHibernateDao.save(SimpleHibernateDao.java:100)
at com.wizarpos.tms.service.AppVersionService.saveAppVersion(AppVersionService.java:119)
at com.wizarpos.tms.service.AppVersionService$$FastClassByCGLIB$$af88d44b.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
at com.wizarpos.tms.aop.audit.AuditLoggingAspect.logAround(AuditLoggingAspect.java:55)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
...
at com.wizarpos.tms.service.AppVersionService$$EnhancerByCGLIB$$55bd8c01.saveAppVersion(<generated>)
at com.wizarpos.tms.web.app.AppVersionValidationAction.save(AppVersionValidationAction.java:87)
at com.wizarpos.tms.web.app.AppVersionValidationAction$$FastClassByCGLIB$$8900de27.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
at com.wizarpos.tms.aop.permission.PermissionAspect.permissionThrowing(PermissionAspect.java:81)
at sun.reflect.GeneratedMethodAccessor81.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
at com.wizarpos.tms.aop.ownerPermission.OwnerPermissionAspect.permissionThrowing(OwnerPermissionAspect.java:89)
at sun.reflect.GeneratedMethodAccessor80.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
...
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)
at com.wizarpos.tms.web.app.AppVersionValidationAction$$EnhancerByCGLIB$$9c75e94e.save(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
..
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
...
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
...
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:242)
...
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:724)
Caused by: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (7044201 > 4194304). You can change this value on the server by setting the max_allowed_packet' variable.
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3798)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2484)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
...
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
... 148 more
补充:Java ,  Java EE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,