各位,小弟现在用hibernate做了个项目,可总是在保存或修改时出现问题,问题如下:09:32:45,546 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI,
no JNDI name configured
09:32:45,546 DEBUG SQL:229 - insert into gongwen (ownerid, sendid, sendname, tit
le, content, senddate, isread, accessories, type, universalid) values (?, ?, ?,
?, ?, ?, ?, ?, ?, ?)
09:32:45,562 WARN JDBCExceptionReporter:57 - SQL Error: 0, SQLState: 01004
09:32:45,562 ERROR JDBCExceptionReporter:58 - Data truncation
09:32:45,562 WARN JDBCExceptionReporter:57 - SQL Error: 8152, SQLState: 22001
09:32:45,562 ERROR JDBCExceptionReporter:58 - 将截断字符串或二进制数据。
09:32:45,562 ERROR SessionImpl:2399 - Could not synchronize database state with
session
net.sf.hibernate.exception.GenericJDBCException: could not insert: [com.km.gongw
en.data.Gongwen#4028807e057f197301057f1e706a0005]我用的是uuid.hex的主键生成universalid,content字段在数据库中是text类型,请问,这是什么原因造成的?但如果只是新增一两个字段,如type,sendid,就没有问题。
望各位不吝赐教。
no JNDI name configured
09:32:45,546 DEBUG SQL:229 - insert into gongwen (ownerid, sendid, sendname, tit
le, content, senddate, isread, accessories, type, universalid) values (?, ?, ?,
?, ?, ?, ?, ?, ?, ?)
09:32:45,562 WARN JDBCExceptionReporter:57 - SQL Error: 0, SQLState: 01004
09:32:45,562 ERROR JDBCExceptionReporter:58 - Data truncation
09:32:45,562 WARN JDBCExceptionReporter:57 - SQL Error: 8152, SQLState: 22001
09:32:45,562 ERROR JDBCExceptionReporter:58 - 将截断字符串或二进制数据。
09:32:45,562 ERROR SessionImpl:2399 - Could not synchronize database state with
session
net.sf.hibernate.exception.GenericJDBCException: could not insert: [com.km.gongw
en.data.Gongwen#4028807e057f197301057f1e706a0005]我用的是uuid.hex的主键生成universalid,content字段在数据库中是text类型,请问,这是什么原因造成的?但如果只是新增一两个字段,如type,sendid,就没有问题。
望各位不吝赐教。
上面的错误是因为有乱码的缘故导致的,你的转码肯定有问题啊。要不你用英文试一下
Gongwen gongwen = gongwenForm.getGongwen();
GongwenDAO gongwenDao = new GongwenDAO();
gongwen = new Gongwen();
gongwen.setIsread("0");
gongwen.setType("1");
//test
gongwen.setSenddate(new Date().toLocaleString());
gongwen.setAccessories("0");
gongwen.setTitle("hahah");
gongwen.setSendid("111");
gongwen.setSendname("weikj");
System.out.println("============================================");
System.out.println("--->title:"+gongwen.getTitle());
gongwenDao.createGongwen(gongwen);
fwd = "savenew";
}
dao数据库操作:
/**
*新增公文
* */
public String createGongwen(Gongwen gongwen) {
Session session = null;
String id = "";
try {
SessionFactory sf = new Configuration().configure()
.buildSessionFactory();
session = sf.openSession();
Transaction tx = session.beginTransaction();
//新增记录
id = (String) session.save(gongwen); tx.commit();
session.close();
}
catch (HibernateException e) {
sessionClose(session);
e.printStackTrace();
}finally{
sessionClose(session);
}
return id;
}
[email protected]
278257162