-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: yes_no type ignored in DML query
PostPosted: Thu Apr 13, 2006 9:53 am 
Newbie

Joined: Wed Feb 11, 2004 7:50 pm
Posts: 10
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.