Monday, 9 September 2013

Getting max length of field in Roo ActiveRecord

Getting max length of field in Roo ActiveRecord

I have a field in my model that looks like this:
@RooJavaBean
@RooToString
@RooJpaActiveRecord
public class Foo{
@Size(max = 256)
private String bar;
}
In my controller, I want to generate a random string to fit the max length.
I tried using this solution, but it throws a NoSuchFieldException (from
the getDeclaredField() call):
int barLength = Foo.class.getDeclaredField("getBar")
.getAnnotation(Column.class).length();
foo.setBar(generateRandomString(barLength));
Trying getDeclaredField("bar") results in the same. What's the correct way
to do this?

No comments:

Post a Comment