Reputation: 935
I want to save an object in data base.
I'm using MySQL data base, but when I try it I get an exception that says: "data is bigger than Column length".
How can I increase the length of my column using hibernate?
Upvotes: 47
Views: 145898
Reputation: 1
You can use both of @Column(size = 50) and @Size(max = 50) annotation, but using @Size(max = 50) is better than @Column(size = 50), because in @Size annotation, Hibernate automatically triggers a validation before it inserts or updates the entity.
@Column(size = 50);
or
@Size(max = 50); //it's better because Hibernate check automatically validation
Upvotes: 0
Reputation: 4046
if your column is varchar
use annotation length
@Column(length = 255)
or use another column type
@Column(columnDefinition="TEXT")
updating answer based on comment:
@Lob
Upvotes: 108
Reputation: 101
Similarly to mychalvlcek's answer, you can use the length attribute for String values, however if you're wanting to set to VARCHAR(MAX) in the database, this solution worked for me in MS SQL:
@Column(length = Integer.MAX_VALUE)
Upvotes: 0
Reputation: 6712
You can use Length annotation for a column. By using it you can maximize or minimize column length. Length annotation only be used for Strings
.
@Column(name = "NAME", nullable = false, length = 50)
@Length(max = 50)
public String getName() {
return this.name;
}
Upvotes: 9
Reputation: 101
@Column(name = Columns.COLUMN_NAME, columnDefinition = "NVARCHAR(MAX)")
max
indicates that the maximum storage size is 2^31-1 bytes (2 GB)
Upvotes: 9
Reputation: 406
You need to alter your table. Increase the column width using a DDL statement.
please see here
http://dba-oracle.com/t_alter_table_modify_column_syntax_example.htm
Upvotes: -1