Hibernate.orgCommunity Documentation
Cassandra is a distributed column family database.
This implementation uses CQL3 over the native wire protocol with java-driver. The currently supported version is Cassandra 2.1.
Support for Cassandra is considered an EXPERIMENTAL feature as of this release.
Should you find any bugs or have feature requests for this dialect, then please open a ticket in the OGM issue tracker.
Configuring Hibernate OGM to use Cassandra is easy:
To add the dependencies via Maven, add the following module:
<dependency>
<groupId>org.hibernate.ogm</groupId>
<artifactId>hibernate-ogm-cassandra</artifactId>
<version>4.2.0.Final</version>
</dependency>
This will pull the cassandra java-driver transparently.
If you’re not using a dependency management tool, copy all the dependencies from the distribution in the directories:
/lib/required
/lib/cassandra
/lib/provided
To get started quickly, pay attention to the following options:
hibernate.ogm.datastore.provider
hibernate.ogm.datastore.host
hibernate.ogm.datastore.database
And we should have you running. The following properties are available to configure Cassandra support:
Cassandra datastore configuration properties
cassandra_experimental
The hostname and port of the Cassandra instance. The optional port is concatenated to the host and separated by a colon. Let’s see a few valid examples:
cassandra.example.com
cassandra.example.com:9043
2001:db8::ff00:42:8329
(IPv6)[2001:db8::ff00:42:8329]:9043
(IPv6 with port requires the IPv6 to be surrounded by square brackets)
Listing multiple initial hosts for fault tolerance is not currently supported.
The default value is 127.0.0.1:9042
. If left undefined, the default port is 9042
.
hibernate.ogm.datastore.host
.
The port used by the Cassandra instance.
Ignored when multiple hosts are defined.
The default value is 9042
.Each Entity type maps to one Cassandra table. Each Entity instance maps to one CQL3 row of the table, each property of the Entity being one CQL3 column.
CQL3 table and column names are always quoted to preserve case consistency with the Java layer, with the table name matching the Entity class and the column names matching the Entity’s properties. The @Table and @Column annotations can be used to override identifier names in the usual manner.
Embedded objects are stored as additional columns in the owning Entitie’s table. The columns are named as EmbeddedTypeName.FieldOfEmbeddedType
The type and field names can be overridden by annotations, but concatenation token delimiter cannot.
CQL3 supports a smaller selection of numeric data types than Hibernate, so the missing types are autotmatically converted. byte and short values are promoted to integer.
CQL3 has no character type, so character is promoted to varchar i.e. String. Strings are UTF-8, not ascii.
CQL3 does not distinguish between byte[] and BLOB types for binary storage. These are handled equivalently.
CQL3 does not have a Calendar type, so these are converted to Dates, which are stores as time offset from the unix epoch.
You can assign id values yourself or let Hibernate OGM generate the value using the
@GeneratedValue
annotation.
The preferred identifier approach in Cassandra is to use UUIDs.
Cassandra does not natively support sequence (auto increment identifiers) at present. This approach is supported though use of an additional table to store sequence state, but incurs additional access overheads that make it undesirable for tables with frequent inserts.
Cassandra does not support transactions. Changes to a single Entity are atomic. Changes to more than one are neither atomic nor isolated.
Cassandra does not distinguish between update and insert operations and will not prevent creation of an Entity with duplicate Id, instead treating it as modification of the existing Entity.