Value too long for column error in testing and how I solved it

4,742 views
Skip to first unread message

jimgardener

unread,
Sep 1, 2011, 9:31:23 AM9/1/11
to play-framework
I was writing the model as
@Entity
class Item{
...
@MaxSize(1000)
public String description;
..
}

When I used postgres as db, and ran the app ,it worked fine.
I used psql to examine the Item table (created without specifying
Column length) and found that,

id | bigint | not null
description | text |
name | character varying(255) |

Then I tried to run tests and it failed at loading data.yml

18:20:11,417 WARN ~ SQL Error: 90005, SQLState: 90005
18:20:11,417 ERROR ~ Value too long for column "DESCRIPTION
VARCHAR(255)": "STRINGDECODE('some big string... (287)"; SQL
statement:
insert into Item (creator_id, description, name, price, id) values
(?, ?, ?, ?, ?) [90005-149]

Then I modified the model and specified column length as below
@Entity
class Item{
...
@MaxSize(1000)
@Column(name="description",length=1000)
public String description;
..
}
Then the test successfully loaded data.yml.


What I am wondering is ,how postgres was able to assign column type of
description as 'text',and that of name as varchar(255) , even without
my specifying column length of 'description'.I know it is not play
specific..but I am curious about this.

Julien Richard-Foy

unread,
Sep 1, 2011, 9:49:16 AM9/1/11
to play-fr...@googlegroups.com
I’m not sure if it is a known limitation of postgres or not, but a
possible way to do is to use the columnDefinition attribute in the
@Column annotation:

@Column(columnDefinition="TEXT")

Regards,
Julien

Reply all
Reply to author
Forward
0 new messages