用structs+hibernate向mysql数据库添加数据出错 映射文件部分:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" ><hibernate-mapping package="com.ntvsc.bugsmanage.data">
<class
name="Tbobstacle"
table="tbobstacle"
>
<id
name="Id"
type="java.lang.Long"
column="ID"
>
<generator class="increment"/>
</id> <property
name="Obsid"
column="OBSID"
type="string"
not-null="true"
length="10"
/>mysql 中表的ddl语句主键部分:
CREATE TABLE `tbobstacle` (
  `ID` bigint(20) NOT NULL auto_increment,
  `OBSID` varchar(10) NOT NULL default '',
....
   PRIMARY KEY  (`OBSID`)错误信息:
17:05:39,191 INFO  [STDOUT] obsAddForm.getObsId() =1
17:05:39,191 INFO  [STDOUT] obsAddForm.getCaseId() =
17:05:39,191 INFO  [STDOUT] address.toString() =CLT036/192.168.145.92
17:05:39,191 INFO  [STDOUT] obs =com.ntvsc.bugsmanage.data.Tbobstacle@e3262f
17:05:39,207 INFO  [STDOUT] Hibernate: select max(ID) from tbobstacle
17:06:02,507 INFO  [STDOUT] FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
17:06:21,197 INFO  [STDOUT] Hibernate: insert into tbobstacle (OBSID, CaseID, Phase, MainActName, OBSActName, FunctionName, EnterActName, EnterTime, Describe, Expound, OccurTime, Priority, CompleteTerm, DestineTime, DestineWorkTime, Reason, MainReason, Countermeasure, CounStatus, EffectArea, Result, CompleteTime, States, IP, Re, DynamicField1, DynamicField2, DynamicField3, DynamicField4, DynamicField5, DynamicField6, DynamicField7, DynamicField8, DynamicField9, DynamicField10, DynamicField11, DynamicField12, DynamicField13, DynamicField14, DynamicField15, DynamicField16, DynamicField17, DynamicField18, DynamicField19, DynamicField20, ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
17:06:21,275 WARN  [JDBCExceptionReporter] SQL Error: 1064, SQLState: 42000
17:06:21,290 ERROR [JDBCExceptionReporter] Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Describe, Expound, OccurTime, Priority, CompleteTerm, DestineTime, DestineWorkTi' at line 1"
17:06:21,290 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
....
Caused by: java.sql.BatchUpdateException: Syntax error or access violation message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Describe, Expound, OccurTime, Priority, CompleteTerm, DestineTime, DestineWorkTi' at line 1"
....
7:06:24,900 INFO  [STDOUT] org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch updateAction部分程序:
if (!(obsAddForm.getObsId() == null || obsAddForm.getObsId().equals(""))) {
obs.setObsid(obsAddForm.getObsId());// &#65533;P&#65533;[&#65533;XID
}else {
obs.setObsid(null);
}
if (!(obsAddForm.getCaseId() == null || obsAddForm.getCaseId().equals(""))) {   obs.setCaseID(obsAddForm.getCaseId());}else {
obs.setCaseID(null);
}
....
comboxContentManage.addSample(obs); comboxContentManage.addSample函数:
public boolean addSample(Object object) {
Session session = cdao.getSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
session.save(object);
tx.commit();
} catch (Exception e) {
e.printStackTrace();
} finally {
session.flush();
session.close();
}
return true;
}
PS: object为持久化类,可以正常从页面来的数据。
运行到tx.commit();捕捉到异常,无法插入数据。