Doubt in POJO Mapping of an entity?

Hello Team,

I don’t know whether this questioned has been asked already or not but after spending many hours I finally decided to post this in forum.
See reference here
I have a POJO class as below

package com.jio.tiny.redirect.model;

import java.io.Serializable;

import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.stereotype.Repository;

import com.couchbase.client.java.repository.annotation.Field;

@Repository
@Scope(value=ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Document
public class JioTURequestCB implements Serializable{

    /**
     * Auto generated SerialVersionUID
     */
    
    private static final long serialVersionUID = 4483410279827782090L;
    
    @Field
    private String clickTime;
    
    @Field
    private String shortUrl;
    
    @Field
    private String referrer;
    
    @Field
    private String userAgent;
    
    @Field
    private String ipAddress;
    
    public String getClickTime() {
        return clickTime;
    }

    public void setClickTime(String clickTime) {
        this.clickTime = clickTime;
    }

    public String getShortUrl() {
        return shortUrl;
    }

    public void setShortUrl(String shortUrl) {
        this.shortUrl = shortUrl;
    }

    public String getReferrer() {
        return referrer;
    }

    public void setReferrer(String referrer) {
        this.referrer = referrer;
    }

    public String getUserAgent() {
        return userAgent;
    }

    public void setUserAgent(String userAgent) {
        this.userAgent = userAgent;
    }

    public String getIpAddress() {
        return ipAddress;
    }

    public void setIpAddress(String ipAddress) {
        this.ipAddress = ipAddress;
    }

}

And then I am performing an insertion operation as below

package com.jio.tiny.redirect.dao.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.couchbase.client.java.Bucket;
import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject;
import com.jio.tiny.redirect.dao.JioTUDAO;
import com.jio.tiny.redirect.model.JioTURequestCB;

@Repository
public class JioTUDAOImpl implements JioTUDAO {
    
    @Autowired
    private Bucket userBucket;

    @Override
    public void sendDataBucket(JioTURequestCB jioTURequestCB) {
        JsonObject content = JsonObject.empty()
                .put("ClickTime", jioTURequestCB.getClickTime().toString())
                .put("ShortUrl", jioTURequestCB.getShortUrl())
                .put("Referrer", jioTURequestCB.getReferrer())
                .put("UserAgent", jioTURequestCB.getUserAgent())
                .put("IpAddress", jioTURequestCB.getIpAddress());
        //atomically get the next sequence number:increment by 1, initialize at 1 if counter doc not found
        String jioTuIdGenerator = userBucket.counter(jioTURequestCB.getShortUrl(), 1, 1).toString();
        JsonDocument doc = JsonDocument.create(jioTuIdGenerator, content);
        userBucket.insert(doc);
    }
    
}

Now the above code is working fine but when I am trying to perform same operation using CB POJO Entity Mapping as follow

    package com.jio.tiny.redirect.dao.impl;

    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Repository;

    import com.couchbase.client.java.Bucket;
    import com.couchbase.client.java.document.EntityDocument;
    import com.jio.tiny.redirect.dao.JioTUDAO;
    import com.jio.tiny.redirect.model.JioTURequestCB;

    @Repository
    public class JioTUDAOImpl implements JioTUDAO {
        
        @Autowired
        private Bucket userBucket;

        @Override
        public void sendDataBucket(JioTURequestCB jioTURequestCB) {
            String jioTuIdGenerator = userBucket.counter(jioTURequestCB.getShortUrl(), 1, 1).toString();
            EntityDocument<JioTURequestCB> doc = EntityDocument.create(jioTuIdGenerator,jioTURequestCB);
            userBucket.insert(doc);
        }
            
    }

The code is running fine without any exception/error but in CB except jioTuIdGenerator value I can’t see anything else. Ideally it should insert the JioTURequestCB data as a document for every request.

I don’t know what’s wrong in my code. Pls help.

It should probably be made more clear in its javadoc, but the EntityDocument<T> is not meant to be used directly on the Bucket.

Rather, use methods available through userBucket.repository().

Does that mean I have to insert like this userBucket.repository().insert(doc);???

That is correct, yes!