简体   繁体   中英

Retrieving map mongo collection in spring-data-mongodb

I am using spring-data-mongo to retrieving these kind of objects of my notifications collection:

_id:ObjectId("123123123123")
1510067387875:Object
    date:"1510067387875"
    title:"Sample title"
    text:"Sample Text"
_id:ObjectId("123223123123")
1110067387875:Object
    date:"1110067387875"
    title:"Sample title"
    text:"Sample Text"

So i've defined my repository class: NotificationRepository

@Repository
@Transactional("mongoTransactionManager")
@PersistenceContext(name = "mongodbEntityManager")
public interface NotificationRepository extends MongoRepository<NotificationMap, ObjectId> {
}

And NotificationMap:

@Document(collection = "notifications")
public class NotificationMap {

@Id
private ObjectId _id;

private Map<String, Notification> map;

/**
 * @return the map
 */
public Map<String, Notification> getMap() {
    return map;
}

/**
 * @param map the map to set
 */
public void setMap(Map<String, Notification> map) {
    this.map = map;
}

public ObjectId get_id() {
    return _id;
}

/**
 * @param _id the _id to set
 */
public void set_id(ObjectId _id) {
    this._id = _id;
}

}

And finally Notification class:

public class Notification {
    private long date;
    private String title;
    private String text;
    private String dateString;

But empty object is returned. How i should to access to the info

NotificationMap seems unnecessary. Just use:

public interface NotificationRepository
  extends MongoRepository<Notification, ObjectId> {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM