MathJax

SyntaxHighlighter

Highlight

Custom CSS

Sunday, April 30, 2006

Yikes! More Hibernate type gotchas!

Suppose your mapping file contains this:

<id name="id" column="uid" type="long" unsaved-value="null">

Then you write this code:

Event e = (Event) session.load(Event.class, 1);

Result:

01:46:14,375 DEBUG LongType:79 - binding '1' to parameter: 1
01:46:14,375  INFO LongType:89 - could not bind value '1' to parameter: 1
java.sql.SQLException: Statement parameter 1 not set.

How sneaky! The type is long, but the literal 1 is an int and will be boxed into an Integer. Darn. Write this and things will work:

Event e = (Event) session.load(Event.class, 1L);
Post a Comment