raju raju - 1 year ago 162
Java Question

Constraints in ebean java play framework not reflected in generated sql

I am using ebean ORM in my java based play framework and following is my model

package models;

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

import com.avaje.ebean.annotation.CreatedTimestamp;
import com.avaje.ebean.annotation.UpdatedTimestamp;

import play.db.ebean.*;
import play.data.validation.*;

@Table(name = "coupons")
public class Coupon extends com.avaje.ebean.Model {

private static final long serialVersionUID = 1L;

private Long id;

private String title;

private String description;

@Column(name = "created_at")
private Date createdAt;

@Column(name = "updated_at")
private Date updatedAt;

@Column(name = "valid_from")
private Date validFrom = new Date();

@Column(name = "valid_to")
private Date validTo = new Date((long)2147483647*1000);


Generated sql file is

create table coupons (
id bigserial not null,
title varchar(255),
description varchar(255),
valid_from timestamp,
valid_to timestamp,
created_at timestamp not null,
updated_at timestamp not null,
constraint pk_coupons primary key (id)

drop table if exists coupons cascade;

Does ebean convert the constraints into sql file? How do I make sure my constraints are reflected in sql file also?

Answer Source

Ebean does not read any of the Play constraint annotations.


So the Required and MaxLength are not read and hence don't effect the generated DDL.

Ebean reads the JPA annotations and the javax.validation.constraints annotations @NotNull and @Size. For example, you could use:

@Size(max = 80)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download