最開始在jBPM4.3執行過程中老是遇到 SQL異常,提示“無效數字”。仔細跟蹤發現,是因爲Hibernate ID策略與jBPM4.3中的一些Model中字段名稱造成的。在Hibernate Reference 中(14.5. Refering to identifier property)有如下描述:
Note: this has changed significantly starting in version 3.2.2. In previous versions, id always referred to the identifier property no matter what its actual name. A ramification of that decision was that non-identifier properties named id could never be referenced in Hibernate queries.
而在jBPM4.3的jbpm.execution.hbm.xml中ExecutionImpl 類有如下配置:
<class name="ExecutionImpl"
table="JBPM4_EXECUTION"
discriminator-value="pvm">
<id name="dbid" column="DBID_">
<generator class="assigned" />
</id>
……
<property name="id" column="ID_" unique="true" />
檢查發現,項目中使用的Hibernate版本是3.2.0。這就是導致錯誤的原因了,在ExecutionImpl類中對id訪問的時候,始終都是訪問的DBID_列。解決方式是將hibernate換成3.2.2以上的版本即可。