Skip to content

Understanding Hecate Annotations

Mark Frazier edited this page Apr 6, 2016 · 22 revisions

Overview

Hecate provides a set of annotations to facilitate easy mapping of POJOs to Cassandra tables. Using these annotations, it is possible to create your schema without writing any CQL statements.

Explanation of Hecate Annotations

@PartitionKey(order=[value])

This will mark a field as part of the Primary Key in the schema. You can have multiple PartitionKey annotations , so long as they are ordered. The ordering is accomplished using the "order" parameter on the annotation

public class MyPojo {
    @PartitionKey(order=0)
    private String key1;
    @PartitionKey(order=1)
    private String key2;
}

Note that the order values can be any value, so long as they can be ordered.

public class MyPojo {
    @PartitionKey(order=42)
    private String key1;
    @PartitionKey(order=43)
    private String key2;
}

Both of these are the equivalent of the following CQL DDL:

CREATE TABLE mypojo (
    key1 text,
    key2 text,  
    PRIMARY KEY (key1, key2)
)

@ClusteringColumn(order=[value])

ClusteringKey can be used to indicate a field belongs a compound key. There can be more than one. Note that each ClusteringKey annotation must also have an order specified if you have ordered the PartitionKey annotations.

public class MyPojo {
    @PartitionKey(order=1)
    private String key1;
    @PartitionKey(order=2)
    private String key2;
    @ClusteringColumn(order=3)
    private String key3;
}

Is equivalent to a CQL DDL that looks like this:

CREATE TABLE mypojo (
    key1 text,
    key2 text,
    key3 text,
    PRIMARY KEY ((key1, key2),key3)
)

@Embedded

allows nesting of Pojos within the Pojo DAO, creates relationship between the two tables?

@Table([value])

Table annotation allows explicit naming of the table generated for this pojo.

Example:

@Table("nametable")
public class MyPojo {
    @PartitionKey(order=1)
    private String key;
    private String field;
}

Equivalent DDL:

CREATE TABLE nametable (
    key text,
    field text,  
    PRIMARY KEY (key)
)

@Column([value])

Column annotation allows explicit naming of the column, rather than using pojo field name.

public class MyPojo {
    @PartitionKey(order=1)
    @Column("firstname")
    private String key;
    @PartitionKey(order=2)
    @Column("lastname")
    private String field;
}

Equivalent DDL:

CREATE TABLE nametable (
    firstname text,
    lastname text,  
    PRIMARY KEY (firstname,lastname)
)

@Cascade(save=[true|false], delete=[true|false])

NEED EXAMPLE

@Ttl([value])

NEED EXAMPLE

@Ignored

Indicates that the annotated field should be ignored for DDL generation.

Clone this wiki locally