Rstrl Rstrl - 7 months ago 37
Java Question

Binding between Java Objects and Records

I have an embedded document based OrientDB database with records and I can't read back the saved entities. A get the right number of elements, but the attributes aren't mapped to my pojo's fields.
What am I doing wrong? Any tips?


OObjectDatabaseTx db = new OObjectDatabaseTx("local:db");
if (db.exists()) {
db = new OObjectDatabaseTx("local:db").open("admin", "admin");
} else {


long cnt = db.countClass(User.class);
System.out.println(cnt); // OK

User user = db.newInstance(User.class, "Firstname", "Lastname", "");

db.begin();; // it's OK, the DB contains this document, I can select it with the servers console

for (User usr : db.browseClass(User.class)) {
System.out.println(usr); // User object with null fields, why?

The User class:

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; = 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) { = email;

public String toString() {
return firstname + " " + lastname + " " + email;



Java objects retrieved directly from OrientDB (as you're doing in this example) are proxied transparently to their underlying records, allowing lazy loading of their fields. In your scenario, you'll have to use the User object get methods in order to trigger the population of the corresponding fields from the DB. The fields have default values (all null in your case) until loaded.

See also: "How It Works" in OrientDB Object2RecordJavaBinding