JPA



extending play.db.jpa.Model


User.java
package models; import java.util.*; import javax.persistence.*; import play.db.jpa.*; @Entity
@Table(name="user_table") public class User extends Model { public String email; public String password; public String fullname; public boolean isAdmin; public User(String email, String password, String fullname) { this.email = email; this.password = password; this.fullname = fullname; } }


PostgreSQL SQL
CREATE TABLE user_table
(
  id bigint NOT NULL,
  email character varying(255),
  fullname character varying(255),
  isadmin boolean NOT NULL,
  "password" character varying(255),
  CONSTRAINT user_table_pkey PRIMARY KEY (id)
)

Bean Validation
@Required
@MinSize(1)
@MaxSize(100)
@Column(name="text", nullable=false, length=100)

public String someText;

Save with Enumeration Type Field and Custom i18n Messages with overriding toString



User.java

@Enitiy
public class User extends Model {
    @Enumerated(javax.persistence.EnumType.STRING)
    public Role role;
}

Role.java

public enum Role {
    MIS {
        public String toString(){
            return Messages.get("MIS");
        }
    }, CEO {
        public String toString(){
            return Messages.get("CEO");
        }
    }
}

messages

MIS = MIS系統工程師
CEO = CEO



Comments