Skip to content
Andrew Horishnii edited this page Dec 1, 2015 · 2 revisions

Annotations

Field annotation:
  • @ColumnAutoInc - used to set field as autoincrement. It applies only to the type of long or Long.class.
  • @ColumnChild - used to set relationship (one to one, one to many).
  • @ColumnDAO - used to save custom type object in the database.
  • @ColumnIgnore - used to ignore this field.
  • @ColumnName - used to set column name. Not required. Default used field name.
  • @ColumnPrimaryKey - used to set field as primary key.
Class annotation:
  • @TableName - used to set table name. Not required. Default used class simple name.

Create entities

Entity class need have private fields, and have default constructor. For example:

public class Artist {
    @ColumnAutoInc private Long id;
    private String name;
    @ColumnChild(foreignKey = "artistId", parentKey = "id") 
    private List<TrackEntity> trackList;

    public Artist() {
    }

    ...
}
@TableName("Track")
public class TrackEntity {
    @ColumnPrimaryKey private long id;
    private Long artistId;
    @ColumnName("name") private String trackName;
    private Date createdAt;

    public TrackEntity() {
    }

    ...
}

Clone this wiki locally