I am using Couchbase 4.0.0 with Spring Data Couchbase 1.3.2, and want to persist the relationships using referenced document instead of embedded. For example, the document is as the following:
{
title: "Some Title",
pages: 123,
publisher: {
name: "O'Reilly Media",
location: "CA"
}
}
But I want the documents like this:
{
_id: "oreilly",
name: "O'Reilly Media",
location: "CA"
}
{
_id: 123456789,
title: "Some Title",
pages: 123,
publisher_id: "oreilly"
}
I have 2 different classes to represent the data and I'm using the annotations @Document
and @Field
. I already tried the annotation @ManyToOne
but it didn't work.
There is currently no support of @ManyToOne
type document relations in Spring Data Couchbase. Quite importantly this annotation is provided by JPA
and not part of Spring Data itself (not a common thing across all the stores backing Spring Data).
Note that 1.3.2
is quite an old version, and the Spring Data Couchbase connector has since then been almost entirely rewritten in 2.0.0
(and 2.1.0
is just around the corner).
There was some significant upgrades to Spring Data Couchbase features in this 2.0.0 version, and that idea of storing sub-objects as separated documents was thrown around, as an idea. It could make it in a future version, but there's no definite roadmap for it. Edit: if that feature gets added, it won't be before at least version 2.2.0