这是我的Action
package model.exam.struts;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import model.exam.hibernate.HibernateService;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;public class AdminCoverModifyTeacherAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
HttpSession httpSession = request.getSession();
Session session = HibernateService.getSession();
Transaction tx = null;
String tid = null;
String password = null;
String tname = null;
String hql = null;
String id = null;
id = httpSession.getAttribute("id").toString();
if (form != null) {
tid = ((AdminCoverModifyTeacherActionForm) form).getT_id();
password = ((AdminCoverModifyTeacherActionForm) form).getPwd();
tname = ((AdminCoverModifyTeacherActionForm) form).getT_name();
} try {
tx = session.beginTransaction();

session
.createQuery(
"update Teacher t set t.t_id=:id,t.pwd=:pwd,t.t_name=:name where t.id=:id")
.setParameter("id", tid).setParameter("pwd", password)
.setParameter("name", tname).setParameter("id", id)
.executeUpdate();

tx.commit(); } catch (Exception e) {
e.printStackTrace();
tx.rollback();
return mapping.getInputForward();
} finally {
session.close();
} return mapping.findForward("success");
}
}
出现的错误如下:
20:17:13,046  WARN FromElementType:349 - Using non-qualified column reference [t_id -> ([t_id])]
20:17:13,062  WARN FromElementType:349 - Using non-qualified column reference [pwd -> ([pwd])]
20:17:13,062  WARN FromElementType:349 - Using non-qualified column reference [t_name -> ([t_name])]
20:17:13,062  WARN FromElementType:349 - Using non-qualified column reference [id -> ([id])]
Hibernate: update teacher set t_id=?, pwd=?, t_name=? where id=?
20:17:13,109  WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: 01004
20:17:13,109 ERROR JDBCExceptionReporter:72 - Data truncation: Column set to default value; NULL supplied to NOT NULL column 't_name' at row 1
org.hibernate.exception.GenericJDBCException: could not execute update query
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
at org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
at org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
at org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
at org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
at model.exam.struts.AdminCoverModifyTeacherAction.execute(AdminCoverModifyTeacherAction.java:46)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at model.exam.struts.EncodingFilter.doFilter(EncodingFilter.java:16)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Column set to default value; NULL supplied to NOT NULL column 't_name' at row 1
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2973)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1600)
at com.mysql.jdbc.ServerPreparedStatement.serverExecute(ServerPreparedStatement.java:1125)
at com.mysql.jdbc.ServerPreparedStatement.executeInternal(ServerPreparedStatement.java:677)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1357)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1274)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1259)
at org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
... 26 more

解决方案 »

  1.   

    supplied to NOT NULL column 't_name' at row 1 tname不能为空
      

  2.   

    tname 不为空呀,HQL语句是不是错误?
      

  3.   

    建议 把setParameter 换成相应的setString setInteget ,但不知道与此有没有关  好像是你的  String tname = null; (你初始化为空串试试)
      

  4.   

    .setParameter("id", tid).setParameter("pwd", password)
                        .setParameter("name", tname).setParameter("id", id)
    ?设置两次id
    ??
      

  5.   


    Using non-qualified column reference [t_id -> ([t_id])] 
    不合格的列名
    t_id我问下你写的是hql么?
      

  6.   

    列 名 不对吗,你可能用的是 数据库 字段名,改成pojo 的属性,试试看看
      

  7.   

    Hql 里用的是pojo里面的属性,不是数据库里面的字段
      

  8.   

    NOT NULL column 't_name' at row 1
    t_name 是 not null  但用了空 ,如果你设置了,请检查确定设置正确了。这些细节问题。注意点该没多大问题!
      

  9.   

    大家有没有发现他在action里面做查询啊
    这本身就不合格
      

  10.   

    supplied to NOT NULL column 't_name' at row 1 tname不能为空