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 one should I choose?
eveytime blogDAO.get(id); the first one every query would load all the User data,
can that be very slow or waste time?
I suggest #3 😉 :
Mongodb good fit for data denormalization, so my opinion is that you need add some user related data to the blog post in order to quick display blog posts list. In case if you need more user info then exists in Blog document (for blog displaying for example) you can load blog first and then user. Also you need update user data within each user blog when he update his profile.