I’m using Sping Data Couchbase with Springboot 2.3.1.RELEASE and Couchbase Server 6.5.1.
I discovered an issue when persisting an object with CouchbaseRepository.save(). I have an Entity as shown below (shortened for emphasis):
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Document
public class Exam implements Serializable {
@Id
private String id;
private SimpleEntry<String, String> examiner;
@Field
private List<SimpleEntry<String, Integer>> papers;
@Field
private List<SimpleEntry<String, Integer>> questionsToAnswer;
public void addQuestionsToAnswer(String paperTitle, int questionCount){
if( questionsToAnswer == null )
questionsToAnswer = new ArrayList<>();
questionsToAnswer.add(new SimpleEntry<>(paperTitle, questionCount));
}
}
The class uses another class SimpleEntry which is just a replica of Map.Entry:
public class SimpleEntry<K, V> implements Map.Entry<K, V>, Serializable {
private K key;
private V value;
public SimpleEntry(){}
public SimpleEntry(K key, V value) {
this.key = key;
this.value = value;
}
@Override
public K getKey() {
return key;
}
@Override
public V getValue() {
return value;
}
@Override
public V setValue(V value) {
V old = this.value;
this.value = value;
return old;
}
public void setKey(K key) {
this.key = key;
}
}
When saving for the examiner
field seems to save ok (not according to the docs) and produces the following when inspected using the admin console:
{
...
"examiner": {
"content": {
"value": "user@example.com",
"key": "Test User"
},
"id": null,
"expiration": 0
},
...
}
However, on retrieval, it returns null for both the key and the value.
Also, for the other two fields, this is what I see from the inspection which failed to even initialize cause its not even an array:
{
...
"questionsToAnswer": {
"empty": false
},
"papers": {
"empty": false
},
...
}
What could be the issue and what might be the solution? I have used this with Mongodb and it works perfectly. I’m trying to move to couchbase and that’s when I started noticing these errors.
I appreciate any help I can get. Thanks.