我可以生成 TEXT 列吗?我的 @Entity 类包含一个字符串,它是产品的摘要,但该字符串生成一个不够大的 VARCHAR(255) 。我可以使用什么来仍然生成表,但将其从 Java 中的 VARCHAR 列更改为 TEXT 列吗?这是一个 Play 应用程序。
实体类关系。
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;
}
由 Java 生成 SQL。
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;
我希望能够做到:
create table product (
...
description text,
...
);
最佳答案
@Column
注解允许通过columnDefinition
参数定义类型,您需要像这样添加
@Column(长度 = 65535,columnDefinition="Text")
关于java - 生成 TEXT 列而不是 VARCHAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42959887/