Hi,
When I use the yes_no type in a DML style query it looks as if the query doesn't use the type because a 0 or a 1 is inserted in the database. And the inserted value varies between setParameter() and the setSerializable(). With setSerializable I think it uses the toString method of the Boolean type because I got an value too long database error when using setSerializable to set the Boolean type on the query. So it probably tried insert 'true' into a char(1) column.
Hibernate version:
3.1.2
Code between sessionFactory.openSession() and session.close():
public int batchUpdatePpms(Collection ppms, Ppm ppm)
throws DataAccessException {
Session session = null;
Transaction transaction = null;
int rowsUpdated = 0;
try {
session = HibernateUtil.getCurrentSession();
HibernateUtil.beginTransaction();
Collection fieldsToUpdate = new ArrayList();
if (ppm.getValidationFlag() != null) {
fieldsToUpdate.add("p.validationFlag = :validationFlag");
}
if (StringUtils.isNotBlank(ppm.getRemark())) {
fieldsToUpdate.add("p.remark = :remark");
}
String fieldsToUpdateString = StringUtils.join(fieldsToUpdate
.iterator(), ',');
// take the keys of the ppms and join them comma
// separated together
String keys = ScStringUtils.join(ppms.iterator(), "key", ',');
Query query = session.createQuery("update Ppm p set "
+ fieldsToUpdateString + " where p.key in (" + keys + ")");
if (ppm.getValidationFlag() != null) {
query.setParameter("validationFlag", ppm.getValidationFlag());
}
if (StringUtils.isNotBlank(ppm.getRemark())) {
query.setString("remark", ppm.getRemark());
}
rowsUpdated = query.executeUpdate();
session.flush();
session.clear();
HibernateUtil.commitTransaction();
} catch (Exception e) {
HibernateUtil.rollbackTransaction();
throw new DataAccessException(e);
} finally {
HibernateUtil.closeSession();
}
return rowsUpdated;
}
Mapping documents:
<hibernate-mapping>
...
<property name="validationFlag" type="yes_no"/>
...
</hibernate-mapping>
Name and version of the database you are using:
Oracle 8.1.7
The generated SQL (show_sql=true):
update CHP_S_PARTS_PER_MILLIONS set validation_flag=? where CLOTR_KEY in (35730 , 37715)
Thanks anyway,
Joris Wijlens
|