views:

531

answers:

3

Hi,

I'm getting a Null ArrayList in a program i'm developing. For testing purposes I created this really small example that still has the same problem. I already tried diferent Primary Keys, but the problem persists.

Any ideas or suggestions?

1-Employee class @PersistenceCapable(identityType = IdentityType.APPLICATION) public class Employee {

@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
private String key;

@Persistent
private ArrayList<String> nicks;

public Employee(ArrayList<String> nicks) {
    this.setNicks(nicks);
}

public String getKey() {
    return key;
}

public void setNicks(ArrayList<String> nicks) {
 this.nicks = nicks;
}

public ArrayList<String> getNicks() {
 return nicks;
}

}

2-EmployeeService

public class BookServiceImpl extends RemoteServiceServlet implements EmployeeService {

public void addEmployee(){

 ArrayList<String> nicks = new ArrayList<String>();
 nicks.add("name1");
 nicks.add("name2");

 Employee employee = new Employee(nicks);

 PersistenceManager pm = PMF.get().getPersistenceManager();
 try {
  pm.makePersistent(employee);
 } finally {
  pm.close();
 }
}

/**
 * @return
 * @throws NotLoggedInException
 * @gwt.typeArgs <Employee>
 */
public Collection<Employee> getEmployees() {

 PersistenceManager pm = getPersistenceManager();

 try {
  Query q = pm.newQuery("SELECT FROM " + Employee.class.getName());

  Collection<Employee> list =
   pm.detachCopyAll((Collection<Employee>)q.execute());

  return list;

 } finally {
  pm.close();
 }
}

}

A: 

Is it significant that in addEmployee, you obtain the persistenceManager like this:

PersistenceManager pm = PMF.get().getPersistenceManager();

but in getEmployees you call it like this

PersistenceManager pm = getPersistenceManager();

without using PMF.get().

Ewan Todd
Thanks for the suggestion. No, it's not significant. It was just a copy-paste error. But it's exactly the same thing. I've changed it anyway and the problem persists.
dvieira
A: 

Have you tried using the developmen tconsole to se if there is values stored in the datastore?

http://localhost:8080/_ah/admin/datastore

Fedearne
yes, i tried that. Everything is well stored.
dvieira
A: 

I changed the code a bit, and everything is normal now, still I don't know what caused this problem.

I'm using Lists now instead of the collections**(1), I return everything as a simple array trough the RPC(2)** and I changed the way I did the query**(3)**.

(1) List results = (List) query.execute();

(2) return (Employee[]) employees.toArray(new Employee[0]);

(3) Query query = pm.newQuery(Employee.class);

dvieira