相忘于江湖

泉涸,鱼相与处于陆,相呴以湿,相濡以沫,不如相忘于江湖。《庄子.大宗师篇》

menuDataProvider.findFirst() failed

Tuesday Jul 10, 2007

When developing my small project based on JSF (Visual Web Pack) on NetBeans 5.5.1, I encountered a weird stuff -- the following codes don't work as expected, I always got 'Something wrong' warnings.

Integer dishID = new Integer(1);
RowKey rkMenu = menuDataProvider.findFirst("id", dishID);
if (rkMenu == null) {
info("Something wrong!!"):
return null;
}
info("You're lucky!!");

 

I found the cause when I tried to do manually searching:

menuDataProvider.refresh();
menuDataProvider.cursorFirst();
Integer curDishID = (Integer) menuDataProvider.getValue("id");

 

There is an Exception in the last line of above code snippet: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer.

This is pretty weird to me, since the property of menu.id is INTEGER in MySQL database. After double checking the design of menu database, I found that menu.id also has a UNSIGNED property. JSF (or Java) will map INTEGER column into Integer datatype, but will map INTEGER|UNSIGNED column into Long datatype. That may be the root cause.

Solution is pretty straightforward -- either remove the UNSIGNED property in database, or use Long datatype when accessing INTEGER|UNSIGNED column.


References:

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed