@Retention(value=RUNTIME) @Target(value=TYPE) @Documented public @interface Immutable
@Table
@Immutable
public class MyImmutableEntity {
@PartitionKey
public final Long sensorId;
@ClusteringColumn
public final Date date;
@Column
public final Double value;
//Correct non-default constructor with matching field name and type
public MyImmutableEntity(long sensorId, Date date, Double value) {
this.sensorId = sensorId;
this.date = date;
this.value = value;
}
// NO GETTER NOR SETTER !!!!!!!!!!!!!!!
}
Example of wrong mapping because constructor argument name does not match field name:
@Table
@Immutable
public class MyImmutableEntity {
@PartitionKey
public final Long sensorId;
@ClusteringColumn
public final Date date;
@Column
public final Double value;
//Incorrect, there is no field name "sensor_id" !!
public MyImmutableEntity(long sensor_id, Date date, Double value) {
this.sensorId = sensorId;
this.date = date;
this.value = value;
}
// NO GETTER NOR SETTER !!!!!!!!!!!!!!!
}
Example of wrong mapping because constructor argument type does not match field type:
@Table
@Immutable
public class MyImmutableEntity {
@PartitionKey
public final Long sensorId;
@ClusteringColumn
public final Date date;
@Column
public final Double value;
//Incorrect, field sensorId is of type Long, not String !!
public MyImmutableEntity(String sensor_id, Date date, Double value) {
this.date = date;
this.value = value;
}
// NO GETTER NOR SETTER !!!!!!!!!!!!!!!
}
Copyright © 2012-2021. All Rights Reserved.