Spring Data MongoDB
  1. Spring Data MongoDB
  2. DATAMONGO-114

UpdateFirst/Multi operations on MongoTemplate not properly using converter to store objects.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Complete
    • Affects Version/s: None
    • Fix Version/s: 1.0 M3
    • Component/s: None
    • Labels:
      None

      Description

      The code posted in the forum looks correct, looks like we are not handling embedded objects correctly for the update case.

        Activity

        Hide
        Jon Brisbin added a comment -

        Pushed a fix for this that uses the currently-configured converter to process the Update spec to properly convert POJOs that were used in the Update.

        Show
        Jon Brisbin added a comment - Pushed a fix for this that uses the currently-configured converter to process the Update spec to properly convert POJOs that were used in the Update.
        Hide
        Jon Brisbin added a comment -

        The fix mentioned previously seems to be working correctly, so closing this issue.

        Show
        Jon Brisbin added a comment - The fix mentioned previously seems to be working correctly, so closing this issue.
        Hide
        Sid added a comment -

        I am using spring-data-mongodb-1.1.0.jar and can still reproduce the issue.

        An embdeded object of an entity cannot be updated using updateFirst. Code errors

        java.lang.RuntimeException: json can't serialize type : class com.activitystream.domain.ASLikeActionDetail
        at com.mongodb.util.JSON.serialize(JSON.java:261)
        at com.mongodb.util.JSON.serialize(JSON.java:161)
        at com.mongodb.util.JSON.serialize(JSON.java:141)
        at com.mongodb.util.JSON.serialize(JSON.java:58)
        at com.mongodb.BasicDBObject.toString(BasicDBObject.java:84)
        at java.lang.String.valueOf(String.java:2826)
        at java.lang.StringBuilder.append(StringBuilder.java:115)
        at com.datastore.nosql.mongodb.repository.CustomMongoRepository.updateFirst(CustomMongoRepository.java:208)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:323)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:308)

        -Sid

        Show
        Sid added a comment - I am using spring-data-mongodb-1.1.0.jar and can still reproduce the issue. An embdeded object of an entity cannot be updated using updateFirst. Code errors java.lang.RuntimeException: json can't serialize type : class com.activitystream.domain.ASLikeActionDetail at com.mongodb.util.JSON.serialize(JSON.java:261) at com.mongodb.util.JSON.serialize(JSON.java:161) at com.mongodb.util.JSON.serialize(JSON.java:141) at com.mongodb.util.JSON.serialize(JSON.java:58) at com.mongodb.BasicDBObject.toString(BasicDBObject.java:84) at java.lang.String.valueOf(String.java:2826) at java.lang.StringBuilder.append(StringBuilder.java:115) at com.datastore.nosql.mongodb.repository.CustomMongoRepository.updateFirst(CustomMongoRepository.java:208) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:323) at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:308) -Sid
        Hide
        Sid added a comment -

        Please ignore. It turned out that there was no default constructor in the embedded object.

        Thx,
        Sid

        Show
        Sid added a comment - Please ignore. It turned out that there was no default constructor in the embedded object. Thx, Sid
        Hide
        Sid added a comment -

        Just wanted to check if this fix is available in Spring Data spring-data-mongodb-1.1.0?

        Show
        Sid added a comment - Just wanted to check if this fix is available in Spring Data spring-data-mongodb-1.1.0?
        Hide
        John Smothers added a comment -

        I'm still having this issue in version 1.1. My pojo looks is a Data class that contains a list of Tags (key/value pairs):

        public class Data implements Serializable

        { private String id = null; private String value = null; private List<Tag> tags = null; // default constructor // constructor with arguments // getter methods // setter methods // equals method // hashCode method }

        public class Tag implements Serializable

        { private String key = null; private String value = null; // default constructor // constructor with arguments // getter methods // setter methods // equals method // hashCode method }

        I get the following exception:
        java.lang.IllegalArgumentException: can't serialize class com.smo.metric.data.shared.model.Tag

        when trying to find Data records that contain a particular Tag with the following code:

        Tag tag = new Tag();
        tag.setKey("aKey");
        tag.setValue("aValue");
        mongoTemplate.find(new Query().addCriteria(Criteria.where("tags").is(tag));

        This works using the Mongo command line using the command:
        db.data.find({ tags :

        { key:'aKey', value:'aValue' }

        })

        Any help would be much appreciated.

        Show
        John Smothers added a comment - I'm still having this issue in version 1.1. My pojo looks is a Data class that contains a list of Tags (key/value pairs): public class Data implements Serializable { private String id = null; private String value = null; private List<Tag> tags = null; // default constructor // constructor with arguments // getter methods // setter methods // equals method // hashCode method } public class Tag implements Serializable { private String key = null; private String value = null; // default constructor // constructor with arguments // getter methods // setter methods // equals method // hashCode method } I get the following exception: java.lang.IllegalArgumentException: can't serialize class com.smo.metric.data.shared.model.Tag when trying to find Data records that contain a particular Tag with the following code: Tag tag = new Tag(); tag.setKey("aKey"); tag.setValue("aValue"); mongoTemplate.find(new Query().addCriteria(Criteria.where("tags").is(tag)); This works using the Mongo command line using the command: db.data.find({ tags : { key:'aKey', value:'aValue' } }) Any help would be much appreciated.

          People

          • Assignee:
            Jon Brisbin
            Reporter:
            Mark Pollack
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: