System Architect at CodeIT Solutions Maringá - PR - Brazil Reginaldo has posted 1 posts at DZone. View Full User Profile

How to Solve "Integer cannot be cast to Long" Problem on Spring Roo

12.18.2010
| 14591 views |
  • submit to reddit
I'm a newbie to Spring Roo and while trying to create an application using Spring  Roo and Vaadin, I suddenly started getting the following message from Spring Roo Shell:
java.lang.Integer cannot be cast to java.lang.Long
And all my Spring Roo environment stopped working.

After "googling" a lot, I've finally found one possible reason to this problem, at least it was my case. So I'd like to share.

In my case I have annotated some fields with @Min(1) or @Max(9) for example, and what I didn't know is that those annotations takes a long parameter, not a integer parameter.

Then after changing @Min(1) to @Min(1L), the same to @Max annotations, the problem has gone and my Spring Roo environment is working again.

Thanx to this post http://www.manning-sandbox.com/thread.jspa?threadID=39831&tstart=0
0
Your rating: None
Published at DZone with permission of its author, Reginaldo L. Russinholi.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Comments

matt inger replied on Sat, 2010/12/18 - 12:54pm

The hibernate query projection is probably returning a Long value, not an Integer value. I had a similar problem with the Count projection when updating from and older 3.x to 3.5 as they changed from Integer to Long at some point (I think between 3.4 and 3.5). Check the hibernate documentation.

oded peer replied on Sun, 2010/12/19 - 6:13am

For Hibernate query projections that return a numeric value the fool-proof way for converting the object to a primitive type is to use the Number class.

e.g. ((Number)yourNumberObject).intValue();

or ((Number)yourNumberObject).longValue();

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.