Reputation: 8913
I have recently added a new column (age) to a database table (user). I am using MS Sql server.
I have a java app that is trying to add a new record to this table. The app uses Hibernate to update the table.
I have a POJO called UserModel. The age column is of type int.
My model is defined as follows:
@NotEmpty
@Column(name = "Age", nullable = false, precision = 10)
public Integer getAge() {
return Age;
}
public void setAge(Integer Age) {
this.Age = Age;
}
@Transient
public boolean isAgeSet() {
return getAge() != null;
}
When I try to enter a row, I get the following error message:
java.lang.ClassCastException: java.lang.Integer
at org.hibernate.validator.NotEmptyValidator.isValid(NotEmptyValidator.java:36)
The age is set in Java code as 12345.
Has anyone any idea why this is happening?
Upvotes: 0
Views: 243
Reputation: 10379
@NotEmpty
can only be used for String
or Collection
type properties.
See API documentation.
You are already using nullable = false
. That should be enough.
Upvotes: 3