0
votes

i am learning how to store and retrieve data with the google app engine and objectify, and set up a test project in intellij-idea. i created a simple entity that looks like this:

ContactType

@Entity
public class ContactType {

@Id
public Long id;
public String name;

    public ContactType(String name){
        this.name = name;
    }
}

before i start testing i delete all saved instances i created before in my servlet:

deleting old data

Objectify ofy = ObjectifyService.ofy();
ObjectifyService.register(ContactType.class);

List<Key<ContactType>> contactTypes = ofy.load().type(ContactType.class).keys().list();
    ofy.delete().keys(contactTypes).now();

after that i save this entity like this:

saving new data

ContactType contactType1 = new ContactType("contactType1");
ContactType contactType2 = new ContactType("contactType2");
ofy.save().entity(contactType1 ).now();
ofy.save().entity(contactType2 ).now();

then i retrieve the objects i just saved like this:

retrieving data

 List<ContactType> list= ofy
                .load()
                .type(ContactType.class)
                .list();

and get the 2 expected objects. but when i comment out the lines that delete and save the old entries, and just want to retrieve the entries that i saved last time (and which i can still see in the development console), and inspect the returned entries with the intellij-idea debugger, i just get this small error message and no stacktrace in the console at all.:

debugging error message

Unable to evaluate the expression Method threw 'com.googlecode.objectify.LoadException' exception.

and when i change the "view as" option from "list" to "toString" in the intellij-idea debugger i get only following information:

enter image description here

so my questions are:

  1. how can i save and retrieve data with objectify?
  2. how can i see a detailed error stacktrace when something goes wrong?
2

2 Answers

0
votes

i finally fixed this problem. when i try to get the size of the returned list and put a try/catch around it then i get an error message that my entity does not have a default constructor without parameters.

    try{
        List<ContactType> list= ofy
            .load()
            .type(ContactType.class)
            .list();  
        int size = list.size();
    }catch(LoadException e){
        String message = e.getMessage();
    }

after adding following construtor everything works fine:

public ContactType(){
    name = "";
}
0
votes

In answer to part 2 of your question, the stacktrace thrown by Objectify includes all the information you need in the wrapped exception. Whatever is catching and logging the exception is apparently suppressing the exception message. This is not default behavior of the GAE dev environment, so I don't know what's going on.