How can I define 'TEXT' type using eBean in Play! framework?

byron1st picture byron1st · Sep 10, 2012 · Viewed 8.2k times · Source

When I define a variable in Model class as a String, it is converted as 'VARCHAR(255)' in DB.

However, I want to save more than 255 because this data is very long text consisting of several paragraphs.

As far as I remember, there is a TEXT type in DB to save very long text.

How can I define TEXT type in Play! framework?

I tried Constraints.MaxLength and Constraints.Max defined in Play! framework api.

However, still 1.sql file (created by Ebean DDL automatically) defines this variable as VARCHAR(255).

Thanks, in advance!

Answer

ndeverge picture ndeverge · Sep 10, 2012

In your model, just use the column definition set as TEXT:

@Entity
public class MyEntity extends Model {

    @Id
    private Long id;

    @Column(columnDefinition = "TEXT")
    private String aLongText;
    ....

}

I already used it with Postgres, don't know if it is ok with other database server.