Lee
Lee

Reputation: 37

Generate TEXT column and not VARCHAR

Is there anyway that I can generate a TEXT column? My @Entity classes contain a String which is a summary of the product but that String generates a VARCHAR(255) which isn't large enough. Is there anything I can use to still generate the tables but change it from a VARCHAR to a TEXT column in Java? It is a Play app.

Entity class -relationships.

package models.products;

import java.util.*;
import javax.persistence.*;

import play.data.format.*;
import play.data.validation.*;

import com.avaje.ebean.*;

import models.shopping.*;

// Product entity managed by Ebean
@Entity
public class Product extends Model {

    @Constraints.Required
    private String name;

    @Constraints.Required
    private String description;

    @Constraints.Required
    private int stock;

    @Constraints.Required
    private double price;
}

SQL Generated by Java.

create table product (
  id                            bigint not null,
  name                          varchar(255),
  description                   varchar(255),
  stock                         integer,
  price                         double,
  trailer                       varchar(255),
  review                        varchar(255),
  constraint pk_product primary key (id)
);
create sequence product_seq;

I want to be able to make it:

create table product (
      ...
      description                   text,
      ...
    );

Upvotes: 0

Views: 508

Answers (1)

Kuba
Kuba

Reputation: 1153

@Column Annotation allows defining type by columnDefinition parameter, you need to add it like

@Column(length = 65535,columnDefinition="Text")

Upvotes: 3

Related Questions