Reputation: 323
I am using Hibernate with MS SQL Server. When I try to store my entity bean, I keep getting: "SQL error 8152 sqlstate 22001" and "String or binary data would be truncated".
I haven't found this issue anywhere.
Upvotes: 5
Views: 19756
Reputation: 2832
The cause of this, for me, was trying to put something too big into a column that can't fit it.
I thought the problem might be something else—nope—I was just checking the wrong column.
My advice is to
Upvotes: 3
Reputation: 323
I finally solved it and wanted to share the solution here, in case anybody else has the same issue.
Normally this this occurs if a column is defined too small (like trying to store a string with 300 characters in a column defined as varchar(256)). But in my case it was different:
Solution: When I defined the table with annotations in hibernate, I defined a link to another table wrongly.
Instead of defining it as many-to-one:
@ManyToOne
public myEntity getMyEntity() {
return myEntity;
}
I defined it as a normal column:
@Column
public myEntity getMyEntity() {
return myEntity;
}
Maybe this helps anybody else.
Upvotes: 8