-->
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.  [ 2 posts ] 
Author Message
 Post subject: CompositeUserType, a Bug in documentation and examples
PostPosted: Mon Feb 27, 2006 10:42 am 
Newbie

Joined: Wed Aug 11, 2004 3:30 am
Posts: 5
Location: Oslo, norway
In the book Hibernate in Action and online examples, the following example occur on the topic of CompositeUserType.

The method nullSafeGet is as follows:
Code:
public Object nullSafeGet(...) throws ... {
  if(resultSet.wasNull()) return null;
  BigDecimal value = resultSet.getBigDecimal(names[0]);
  ...
  return new MonetaryAmount(value, currency);
}


But the javadoc on jdk 1.5 states the following on the wasNull method:
Quote:
boolean java.sql.ResultSet.wasNull()
Reports whether the last column read had a value of SQL NULL. Note that you must first call one of the getter methods on a column to try to read its value and then call the method wasNull to see if the value read was SQL NULL.


And as you can see from the code, there has been no call to any of the getters prior to the wasNull() call.

The result, at least for me, was that the nullSafeGet method allways returned null!

The fix is ofcourse to move the line:
Code:
BigDecimal value = resultSet.getBigDecimal(names[0]);

above the line
Code:
  if(resultSet.wasNull()) return null;

this does not generate an error even when the resultSet.wasNull is true.

This is not a bug in hibernate, but bad examples can be costly on the users.

Simen.


Top
 Profile  
 
 Post subject: yes
PostPosted: Wed Mar 01, 2006 2:25 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Yes, one unlucky soul had the problem
http://forum.hibernate.org/viewtopic.ph ... highlight=

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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

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.