Jerry Jacob's Blog

Own ID Column for the Model in the Play! Framework

Posted in Java/ J2EE, Play Framework by jerlinworld on January 11, 2012

When you create Model entities in the Play! Framework, Play will provide a default id column.  If you need to use your own id column — say if you are given a database schema to work with — then you should extend a different Play class called GenericModel instead of Model class.  In addition to providing an @Id annotation, it also provides @GeneratedValue annotation. Here is its usage both with  Oracle and MySql.

public class Tutorial extends GenericModel {
@GeneratedValue(strategy = GenerationType.AUTO)
public Long tutorial_id;


@GeneratedValue(strategy=SEQUENCE, generator="videoIdSeq")
@SequenceGenerator(name="videoId", sequenceName="video_id_seq", allocationSize=1)
protected Long videoId;