I'm learning morphine but confused with DBRef

1

@Entity
public class Blog {
   @Id ObjectId id;
   @reference User author;
   String content;
}

or

2

@Entity
public class Blog {
   @Id ObjectId id;
   ObjectId authorId;
   String content;
}

which should i choose?

eveytime blogDAO.get (id); the first one in every request will load all user data, can it be very slow or unnecessary?

+3
source share
3 answers

I suggest # 3;):

@Entity
public class Blog {
   @Id ObjectId id;
   ObjectId authorId;
     ...
   String firstName;
   String lastName;
     ...
   String content;
}

Mongodb is well suited for denormalizing data, so I believe you need to add some user-related data to your blog post in order to quickly display a list of blog posts. If you need more information about the user, then in the Blog document (for example, to display the blog), you can first download the blog, and then the user. You also need to update user data on each user blog when it updates its profile.

+2

- :

@Entity
public class Blog {
   @Id ObjectId id;
   @Reference(lazy = true) User author;

, . , User, Morphia .

. cglib proxytools . .: http://code.google.com/p/morphia/wiki/Dependencies

+1

, http://valyagolev.net/article/mongo_dbref/. DBRefs.

, DBRefs, . ( ) , .

, , , dbref .

0

All Articles