Composite primary key in repository supported?

2,192 views
Skip to first unread message

Jens Rantil

unread,
Jul 1, 2014, 6:14:09 AM7/1/14
to spring-dat...@googlegroups.com
Hi,

Are composite primary keys supported in CrudRepository? I mean, could I implement my own @PrimaryKeyClass and use as ID type for a repository?

Cheers,
Jens

David Webb (Prowave)

unread,
Jul 1, 2014, 8:34:52 AM7/1/14
to Jens Rantil, spring-dat...@googlegroups.com
Check out Section 4.6.1 in the Reference Guide on how to define Composite Keys, then you can use this Repository with your defined key 

TypedIdCassandraRepository

You can also define a Composite Primary key (without a separate class) in your @Table annotated Entity, then use CassandraRepository<T>.  This is the preferred way and the simplest way. :)


/**
* @author David Webb
*
*/
public interface HostInfoRepository extends CassandraRepository<HostInfo> {

}

/**
* @author David Webb
*
*/
@Table(value = "host_info")
public class HostInfo {

@PrimaryKeyColumn(ordinal = 0, name = "cluster_id", type = PrimaryKeyType.PARTITIONED)
private UUID clusterId;

@PrimaryKeyColumn(ordinal = 1, type = PrimaryKeyType.CLUSTERED, ordering = Ordering.ASCENDING)
private String host;

private String hostName;

@Column("data_file_location")
private List<String> dataFileLocations;

@Column("commit_log_location")
private String commitLogLocation;

@Column("saved_cache_location")
private String savedCacheLocation;

@Column("release_version")
private String releaseVersion;

private List<String> tokens;

@Column("compaction_throughput")
private Integer compactionThroughput;

@Column("streaming_throughput")
private Integer streamingThroughput;

@Column("schema_version")
private String schemaVersion;

@Column("operation_mode")
private String operationMode;

@Column("native_transport_running")
private Boolean nativeTransportRunning;

@Column("rpc_server_running")
private Boolean rpcServerRunning;

@Column("partitioner_name")
private String paritionerName;

@Column("local_host_id")
private String localHostId;


}

--
You received this message because you are subscribed to the Google Groups "Spring Data Cassandra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spring-data-cass...@googlegroups.com.
To post to this group, send email to spring-dat...@googlegroups.com.
Visit this group at http://groups.google.com/group/spring-data-cassandra.
To view this discussion on the web visit https://groups.google.com/d/msgid/spring-data-cassandra/1b054ef2-26ba-4c44-b9eb-a260f4a45ccf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages