_class property in CouchBase
I have a document stored in Couchbase.
"a":
"b":
"key":"Value"
,
"_class":"com.nikhil.model"
,
"c":
"d":
"key":"value"
,
// _class is missing here
,
"_class": "com.nikhil.model"
Here as you can see I don't have an _class inside the "d" in the doucument because of this I am not able to get this document. An object mapping exception came.
_class is used to map the nested object of couchbase to the model required for mapping but inside the "c" object I don't have this _Class property that is why a mapping exception comes.
Is there any fix for this?
couchbase spring-data-couchbase
add a comment |
I have a document stored in Couchbase.
"a":
"b":
"key":"Value"
,
"_class":"com.nikhil.model"
,
"c":
"d":
"key":"value"
,
// _class is missing here
,
"_class": "com.nikhil.model"
Here as you can see I don't have an _class inside the "d" in the doucument because of this I am not able to get this document. An object mapping exception came.
_class is used to map the nested object of couchbase to the model required for mapping but inside the "c" object I don't have this _Class property that is why a mapping exception comes.
Is there any fix for this?
couchbase spring-data-couchbase
This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)
– Matthew Groves
Nov 15 '18 at 14:57
add a comment |
I have a document stored in Couchbase.
"a":
"b":
"key":"Value"
,
"_class":"com.nikhil.model"
,
"c":
"d":
"key":"value"
,
// _class is missing here
,
"_class": "com.nikhil.model"
Here as you can see I don't have an _class inside the "d" in the doucument because of this I am not able to get this document. An object mapping exception came.
_class is used to map the nested object of couchbase to the model required for mapping but inside the "c" object I don't have this _Class property that is why a mapping exception comes.
Is there any fix for this?
couchbase spring-data-couchbase
I have a document stored in Couchbase.
"a":
"b":
"key":"Value"
,
"_class":"com.nikhil.model"
,
"c":
"d":
"key":"value"
,
// _class is missing here
,
"_class": "com.nikhil.model"
Here as you can see I don't have an _class inside the "d" in the doucument because of this I am not able to get this document. An object mapping exception came.
_class is used to map the nested object of couchbase to the model required for mapping but inside the "c" object I don't have this _Class property that is why a mapping exception comes.
Is there any fix for this?
couchbase spring-data-couchbase
couchbase spring-data-couchbase
edited Nov 16 '18 at 14:26
Matthew Groves
16.3k855105
16.3k855105
asked Nov 15 '18 at 5:49
NikhilNikhil
18813
18813
This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)
– Matthew Groves
Nov 15 '18 at 14:57
add a comment |
This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)
– Matthew Groves
Nov 15 '18 at 14:57
This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)
– Matthew Groves
Nov 15 '18 at 14:57
This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)
– Matthew Groves
Nov 15 '18 at 14:57
add a comment |
3 Answers
3
active
oldest
votes
If you are using Spring boot, you need to override the typekey()
method in the Couchbase Config file which extends AbstractCouchbaseConfiguration
and return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE
. This will replace your _class with javaClass
string in the documents stored in Couchbase Server. I hope this helps.
@Configuration
public class RemoteCouchbaseConfiguration extends AbstractCouchbaseConfiguration
@Value("$couchbase.host")
private String host;
@Value("$couchbase.bucket.bucketName")
private String bucketName;
@Value("$couchbase.bucket.password")
private String password;
@Override
protected List<String> getBootstrapHosts()
return Arrays.asList(this.host);
@Override
protected String getBucketName()
return this.bucketName;
@Override
protected String getBucketPassword()
return this.password;
@Override
public String typeKey()
return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;
add a comment |
Looks like you are using Couchbase with Spring Data, the easiest way is to return a projection:
@Override
public List<UserVO> getUsers(String companyId, List<String> userIds)
String queryString = "SELECT meta(t).id as id, t.login as login, t.firstName as firstName from " + getBucketName() + " t where t."+getClassFilter()+" "
+ " and t.companyId = '" + companyId + "' and t.isEnabled = true and t.isVisible = true "
+ " and meta(t).id in ["+userIds.stream().map(e->"'"+e+"'").collect( Collectors.joining( "," )) +"]";
N1qlParams params = N1qlParams.build().consistency(ScanConsistency.NOT_BOUNDED).adhoc(true);
ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);
return userRepository.getCouchbaseOperations().findByN1QLProjection(query, UserVO.class);
1
Cannot we do this using Spring repository like using JPA ?
– Nikhil
Nov 16 '18 at 5:40
1
No, but there is already a ticket requesting this feature.
– deniswsrosa
Nov 16 '18 at 9:51
add a comment |
You could add _class to it using an UPDATE N1QL statement like this:
UPDATE mybucket b
SET b.c.d._class = 'com.foo.bar'
WHERE b.c.d IS NOT MISSING
AND b.c.d._class IS MISSING
That will update any document that has a 'd' object within a 'c' object but doesn't have a '_class' within the c object.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313187%2fclass-property-in-couchbase%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you are using Spring boot, you need to override the typekey()
method in the Couchbase Config file which extends AbstractCouchbaseConfiguration
and return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE
. This will replace your _class with javaClass
string in the documents stored in Couchbase Server. I hope this helps.
@Configuration
public class RemoteCouchbaseConfiguration extends AbstractCouchbaseConfiguration
@Value("$couchbase.host")
private String host;
@Value("$couchbase.bucket.bucketName")
private String bucketName;
@Value("$couchbase.bucket.password")
private String password;
@Override
protected List<String> getBootstrapHosts()
return Arrays.asList(this.host);
@Override
protected String getBucketName()
return this.bucketName;
@Override
protected String getBucketPassword()
return this.password;
@Override
public String typeKey()
return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;
add a comment |
If you are using Spring boot, you need to override the typekey()
method in the Couchbase Config file which extends AbstractCouchbaseConfiguration
and return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE
. This will replace your _class with javaClass
string in the documents stored in Couchbase Server. I hope this helps.
@Configuration
public class RemoteCouchbaseConfiguration extends AbstractCouchbaseConfiguration
@Value("$couchbase.host")
private String host;
@Value("$couchbase.bucket.bucketName")
private String bucketName;
@Value("$couchbase.bucket.password")
private String password;
@Override
protected List<String> getBootstrapHosts()
return Arrays.asList(this.host);
@Override
protected String getBucketName()
return this.bucketName;
@Override
protected String getBucketPassword()
return this.password;
@Override
public String typeKey()
return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;
add a comment |
If you are using Spring boot, you need to override the typekey()
method in the Couchbase Config file which extends AbstractCouchbaseConfiguration
and return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE
. This will replace your _class with javaClass
string in the documents stored in Couchbase Server. I hope this helps.
@Configuration
public class RemoteCouchbaseConfiguration extends AbstractCouchbaseConfiguration
@Value("$couchbase.host")
private String host;
@Value("$couchbase.bucket.bucketName")
private String bucketName;
@Value("$couchbase.bucket.password")
private String password;
@Override
protected List<String> getBootstrapHosts()
return Arrays.asList(this.host);
@Override
protected String getBucketName()
return this.bucketName;
@Override
protected String getBucketPassword()
return this.password;
@Override
public String typeKey()
return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;
If you are using Spring boot, you need to override the typekey()
method in the Couchbase Config file which extends AbstractCouchbaseConfiguration
and return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE
. This will replace your _class with javaClass
string in the documents stored in Couchbase Server. I hope this helps.
@Configuration
public class RemoteCouchbaseConfiguration extends AbstractCouchbaseConfiguration
@Value("$couchbase.host")
private String host;
@Value("$couchbase.bucket.bucketName")
private String bucketName;
@Value("$couchbase.bucket.password")
private String password;
@Override
protected List<String> getBootstrapHosts()
return Arrays.asList(this.host);
@Override
protected String getBucketName()
return this.bucketName;
@Override
protected String getBucketPassword()
return this.password;
@Override
public String typeKey()
return MappingCouchbaseConverter.TYPEKEY_SYNCGATEWAY_COMPATIBLE;
answered Jan 15 at 21:53
awasumawasum
213
213
add a comment |
add a comment |
Looks like you are using Couchbase with Spring Data, the easiest way is to return a projection:
@Override
public List<UserVO> getUsers(String companyId, List<String> userIds)
String queryString = "SELECT meta(t).id as id, t.login as login, t.firstName as firstName from " + getBucketName() + " t where t."+getClassFilter()+" "
+ " and t.companyId = '" + companyId + "' and t.isEnabled = true and t.isVisible = true "
+ " and meta(t).id in ["+userIds.stream().map(e->"'"+e+"'").collect( Collectors.joining( "," )) +"]";
N1qlParams params = N1qlParams.build().consistency(ScanConsistency.NOT_BOUNDED).adhoc(true);
ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);
return userRepository.getCouchbaseOperations().findByN1QLProjection(query, UserVO.class);
1
Cannot we do this using Spring repository like using JPA ?
– Nikhil
Nov 16 '18 at 5:40
1
No, but there is already a ticket requesting this feature.
– deniswsrosa
Nov 16 '18 at 9:51
add a comment |
Looks like you are using Couchbase with Spring Data, the easiest way is to return a projection:
@Override
public List<UserVO> getUsers(String companyId, List<String> userIds)
String queryString = "SELECT meta(t).id as id, t.login as login, t.firstName as firstName from " + getBucketName() + " t where t."+getClassFilter()+" "
+ " and t.companyId = '" + companyId + "' and t.isEnabled = true and t.isVisible = true "
+ " and meta(t).id in ["+userIds.stream().map(e->"'"+e+"'").collect( Collectors.joining( "," )) +"]";
N1qlParams params = N1qlParams.build().consistency(ScanConsistency.NOT_BOUNDED).adhoc(true);
ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);
return userRepository.getCouchbaseOperations().findByN1QLProjection(query, UserVO.class);
1
Cannot we do this using Spring repository like using JPA ?
– Nikhil
Nov 16 '18 at 5:40
1
No, but there is already a ticket requesting this feature.
– deniswsrosa
Nov 16 '18 at 9:51
add a comment |
Looks like you are using Couchbase with Spring Data, the easiest way is to return a projection:
@Override
public List<UserVO> getUsers(String companyId, List<String> userIds)
String queryString = "SELECT meta(t).id as id, t.login as login, t.firstName as firstName from " + getBucketName() + " t where t."+getClassFilter()+" "
+ " and t.companyId = '" + companyId + "' and t.isEnabled = true and t.isVisible = true "
+ " and meta(t).id in ["+userIds.stream().map(e->"'"+e+"'").collect( Collectors.joining( "," )) +"]";
N1qlParams params = N1qlParams.build().consistency(ScanConsistency.NOT_BOUNDED).adhoc(true);
ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);
return userRepository.getCouchbaseOperations().findByN1QLProjection(query, UserVO.class);
Looks like you are using Couchbase with Spring Data, the easiest way is to return a projection:
@Override
public List<UserVO> getUsers(String companyId, List<String> userIds)
String queryString = "SELECT meta(t).id as id, t.login as login, t.firstName as firstName from " + getBucketName() + " t where t."+getClassFilter()+" "
+ " and t.companyId = '" + companyId + "' and t.isEnabled = true and t.isVisible = true "
+ " and meta(t).id in ["+userIds.stream().map(e->"'"+e+"'").collect( Collectors.joining( "," )) +"]";
N1qlParams params = N1qlParams.build().consistency(ScanConsistency.NOT_BOUNDED).adhoc(true);
ParameterizedN1qlQuery query = N1qlQuery.parameterized(queryString, JsonObject.create(), params);
return userRepository.getCouchbaseOperations().findByN1QLProjection(query, UserVO.class);
answered Nov 15 '18 at 19:46
deniswsrosadeniswsrosa
764619
764619
1
Cannot we do this using Spring repository like using JPA ?
– Nikhil
Nov 16 '18 at 5:40
1
No, but there is already a ticket requesting this feature.
– deniswsrosa
Nov 16 '18 at 9:51
add a comment |
1
Cannot we do this using Spring repository like using JPA ?
– Nikhil
Nov 16 '18 at 5:40
1
No, but there is already a ticket requesting this feature.
– deniswsrosa
Nov 16 '18 at 9:51
1
1
Cannot we do this using Spring repository like using JPA ?
– Nikhil
Nov 16 '18 at 5:40
Cannot we do this using Spring repository like using JPA ?
– Nikhil
Nov 16 '18 at 5:40
1
1
No, but there is already a ticket requesting this feature.
– deniswsrosa
Nov 16 '18 at 9:51
No, but there is already a ticket requesting this feature.
– deniswsrosa
Nov 16 '18 at 9:51
add a comment |
You could add _class to it using an UPDATE N1QL statement like this:
UPDATE mybucket b
SET b.c.d._class = 'com.foo.bar'
WHERE b.c.d IS NOT MISSING
AND b.c.d._class IS MISSING
That will update any document that has a 'd' object within a 'c' object but doesn't have a '_class' within the c object.
add a comment |
You could add _class to it using an UPDATE N1QL statement like this:
UPDATE mybucket b
SET b.c.d._class = 'com.foo.bar'
WHERE b.c.d IS NOT MISSING
AND b.c.d._class IS MISSING
That will update any document that has a 'd' object within a 'c' object but doesn't have a '_class' within the c object.
add a comment |
You could add _class to it using an UPDATE N1QL statement like this:
UPDATE mybucket b
SET b.c.d._class = 'com.foo.bar'
WHERE b.c.d IS NOT MISSING
AND b.c.d._class IS MISSING
That will update any document that has a 'd' object within a 'c' object but doesn't have a '_class' within the c object.
You could add _class to it using an UPDATE N1QL statement like this:
UPDATE mybucket b
SET b.c.d._class = 'com.foo.bar'
WHERE b.c.d IS NOT MISSING
AND b.c.d._class IS MISSING
That will update any document that has a 'd' object within a 'c' object but doesn't have a '_class' within the c object.
answered Nov 15 '18 at 14:59
Matthew GrovesMatthew Groves
16.3k855105
16.3k855105
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53313187%2fclass-property-in-couchbase%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
This json isn't valid (even when removing the comment), you may want to update it for accuracy (check out jsonlint.com if you need help)
– Matthew Groves
Nov 15 '18 at 14:57