What is fastest, @Entity or @Embedded?
Im new (today) to the NoSql MongoDb and trying to understand the Morphia.
I want to have one @Entity like this:If i have 3 Tables (Collections) named
Stat Friendlist Userdata I save UserData.Class in Userdata right and Statistic.Class in Stat and so on...My thought was if i give each user a unique ObjectId UUID nr and then every Statistic and FriendList having this UUID nr as there ObjectId. Because if the program need to run statistic only, it will load/work against Statistic only.
@Entity
public class UserData {
@Id private ObjectId id = "UUID 123456789;
public String userName = "";
public String password = "";
@Embedded
private Statistic statistic;
@Embedded
private FriendList friendList;
}
If there are like 18000/hour request to get the UserData would it not be faster to declare them like this:
( i use the same ObjectId and they ares stored in separate Collections (tables)@Entity
public class UserData {
@Id private ObjectId id = "UUID 123456789;
public String userName = "";
public String password = "";
}
@开发者_运维知识库Entity
public class Statistic {
@Id private ObjectId id = "UUID 123456789;
public int loginTimes;
public String gps;
}
@Entity
public class FriendList {
@Id private ObjectId id = "UUID 123456789;
public ArrayList<String> fiends;
}
I think that the correct is use DBRef or Embedded.
If you want some object of the list in other object too, use DBRef, if not, use embedded.
For example, in a blog post, the comments will never be used in another post, so, its embedded.
So, use somehting like:
@Entity
public class UserData {
@Id private ObjectId id = "UUID 123456789;
public String userName = "";
public String password = "";
@Embedded
private Statistic statistic;
@Embedded
private List<Friends> friendList;
}
hope it helps.
Embedded is always faster because Reference stored in different physical location.
精彩评论