user1154457
user1154457

Reputation: 1

Play framework - database table generator

I am new to Play framework. I am using play 1.2.4 and Postgres 9.1.1. Here is my code:

import javax.persistence.Entity;
import play.db.jpa.Model;
import play.data.validation.MaxSize;
import play.data.validation.Required;

@Entity
public class User extends Model {
    @Required
    @MaxSize(20)
    public String name;
}

When I run my application, play framework automatically generates the 'user' table. The column name is defined as character varying(255) and not character varying(20) NOT NULL as I would expect.

Column | Type | Modifiers
-------------+------------------------+-----------
 id | bigint | not null
 name | character varying(255) |

Since I am using validateAndSave() method and I need both @Required and @MaxSize annotations to be present. I could have also used the @Column(nullable=false, length=20) annotation, which by itself does not work with play's validateAndSave() method , but in that case I would end up having “duplicating” annotations.

Upvotes: 0

Views: 645

Answers (1)

Codemwnci
Codemwnci

Reputation: 54884

The @MaxSize is a validation annotation, not a JPA annotation.

You need to use

@Column(length=20) 

Upvotes: 2

Related Questions