我有一個嵌入式文檔的OrientDB數據庫與記錄,我不能回讀保存的實體。獲取正確數量的元素,但屬性未映射到我的pojo字段。 我在做什麼錯?有小費嗎?Java對象與記錄之間的綁定
謝謝!
OObjectDatabaseTx db = new OObjectDatabaseTx("local:db");
if (db.exists()) {
db = new OObjectDatabaseTx("local:db").open("admin", "admin");
} else {
db.create();
}
db.getEntityManager().registerEntityClass(User.class);
long cnt = db.countClass(User.class);
System.out.println(cnt); // OK
User user = db.newInstance(User.class, "Firstname", "Lastname", "[email protected]");
db.begin();
db.save(user); // it's OK, the DB contains this document, I can select it with the servers console
db.commit();
for (User usr : db.browseClass(User.class)) {
System.out.println(usr); // User object with null fields, why?
}
用戶等級:
public class User {
private String firstname;
private String lastname;
private String email;
public User() {
}
public User(String firstname, String lastname, String email) {
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return firstname + " " + lastname + " " + email;
}
}
感謝您的答案! – Rstrl