【问题标题】:Access to DAO in model - Spring Data MongoDB访问模型中的 DAO - Spring Data MongoDB
【发布时间】:2013-07-09 10:49:27
【问题描述】:

可以访问模型中的 DAO。我在 MongoDB 中描述了集合“项目”的模型,如下所示:

@Component
@Document( collection = "item" )
public class Item
{

    @Id
    private ObjectId id;

    private Integer     authId;

    @Autowired
    @Qualifier("mongoItemDao")
    private AuthorDao dao; 

    public Author getAuthor()
    {
         dao.findById(this.authId);
    }

    /* Others setters and getters */
}

如您所见,我指的是从“项目”集合到“作者”集合(一对多关系),我需要在请求时获取确切的对象。我相信 Hibernate 在后台做了类似的事情。

在 app-context.xml 我有

    <context:component-scan base-package="eu.cloudscale.showcase.db.dao.mongo.impl" />

DAO 的实现在哪里。

【问题讨论】:

    标签: java spring mongodb dao spring-data-mongodb


    【解决方案1】:

    应该尝试:

    @Component
    @Document( collection = "item" )
    public class Item
    {
    
        @Id
        private ObjectId id;
    
        private Integer     authId;
    
        @DBRef
        private Author author; 
    
        /* Others setters and getters */
    }
    

    【讨论】:

      猜你喜欢
      • 2012-08-13
      • 1970-01-01
      • 2013-10-03
      • 2013-03-12
      • 1970-01-01
      • 1970-01-01
      • 2014-07-22
      • 2014-05-11
      • 1970-01-01
      相关资源
      最近更新 更多