Reputation: 125
I'm trying to connect to cassandra database using spring data (preferably jpa). I can not find any clera example how to do it, no guide. I found some for MongoDB and Neo4j, but none for cassandra. On mail page of spring there is a mention of coassandra project but none exmaple or guide is provided. Can any one help?
Upvotes: 0
Views: 5649
Reputation: 608
I used spring-data-cassandra-1.1.2.RELEASE. Here are 2 links which provide you detailed steps to configure Cassandra with Spring Data: link1 and link2.
I followed the XML configuration way mentioned in link2, but faced one problem. I guess the ticket for this problem is here and is still open. This problem was resolved by just removing the id attribute from <cassandra:template id="cassandraTemplate" />
. This code is from the config xml shown in the section 4.3.2 of link2.
Apart from this I did not face any problems and the Spring data Cassandra integration worked fine.
Section 5.1 from this link can also be used.
Upvotes: 1
Reputation: 741
Which version of spring-data-cassandra are you using?
For v.1 see http://docs.spring.io/spring-data/cassandra/docs/1.1.0.RC1/reference/html/#cassandra-connectors
I'm using v.2 and also had problems with finding tutorials/examples. But there are test inside the lib itself. See eg. spring-data-cassandra/cassandra/src/test/resources/org/springdata/cassandra/test/integration/config/XmlConfigTest-context.xml - you need to change only few things to make it work with your DB. When cofig is ready you can use CqlOperations to run your queries:
@Autowired
private CqlOperations cassandraTemplate;
cassandraTemplate.buildSaveNewOperation(new Foo("bar")).execute();
And that's basically it :)
Upvotes: 1