日期:2014-05-19  浏览次数:20688 次

Hibernate修改操作
先贴错误信息
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute update query at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:110)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:421)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:283)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1169)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:117)
at com.fyeun.dao.impl.EmployeMessageDaoImpl.updateByEmploye(EmployeMessageDaoImpl.java:53)
at com.fyeun.service.impl.EmployeMessageServiceImpl.updateByEmploye(EmployeMessageServiceImpl.java:37)
at com.fyeun.service.impl.EmployeMessageServiceImpl$$FastClassByCGLIB$$ccc4af60.invoke(<generated>)
at net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:700)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
at com.fyeun.service.impl.EmployeMessageServiceImpl$$EnhancerByCGLIB$$83200424.updateByEmploye(<generated>)
at com.fyeun.test.Test.main(Test.java:39)
Caused by: java.sql.SQLException: General error message from server: "Incorrect string value: '\xC4\xD0' for column 'sex' at row 1"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1278)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2251)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1772)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1619)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:101)
... 17 more

我是拼接字符串进行修改的 代码
Java code


    public void updateByEmploye( String sex,  Integer age,
             String phone,  String address,  String emial,
             Integer usernameId) {
        // TODO Auto-generated method stub
        //Transaction tx;
        Session session = this.getSession();
        //tx = session.beginTransaction();
        String hql = "update Employe set sex='"