Note that there are some explanatory texts on larger screens.

plurals
  1. POGAE GWT JDO persistent List<Element> does not save/load correctly
    primarykey
    data
    text
    <p>I'm worring about JDO in GAE (Google App Engine). (GWT 2.4 and GAE 1.6.3 SDK and JDO 2.3)</p> <p>I have a class "Users" which should save a Collection of "User" in a List, but it doesn't work.</p> <p>When i save my Users-Class, then it creates the "Users"-Object in the Datebase and it also creates the User-Object in the List users. But when i load the Users-Object from the Database, the List users is empty... Do i have to load the list by my self? I guess that JDO schould load the list directy, when i load the Users-Object.</p> <p>I need your Help here! Thanks in previous!</p> <p>Could it be a Problem that i create the Key in abstract class PersistentUser and PersistentUsers? Could the LinkedList be the Problem?</p> <p>My Code:</p> <pre><code>@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true") @Version(strategy=VersionStrategy.VERSION_NUMBER) public class Users extends PersistentUsers implements Serializable{ /** * */ private static final long serialVersionUID = -21666269538993247L; /** * Mapped from Operator X */ @Persistent private String operatorId; @Persistent(mappedBy="userlist") @Element(dependent = "true") private List&lt;User&gt; users; /** * * List of Ids of Users * */ @Persistent(serialized = "true") @Element(dependent = "true") private List&lt;String&gt; userIds; /** * @return the users */ public List&lt;User&gt; getUsers() { return users; } /** * @param users the users to set */ public void setUsers(List&lt;User&gt; users) { this.users = users; } ... } </code></pre> <p>The User Class:</p> <pre><code>@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true") @Version(strategy=VersionStrategy.VERSION_NUMBER) public class User extends PersistentUser implements Serializable{ /** * */ private static final long serialVersionUID = 6899284258473985914L; @Persistent private String emailAddress; @Persistent private UserRole role; /** * * Mapped from Userlist X from Operator Y */ @Persistent private Users userlist; public User(String email, UserRole role){ this.emailAddress = email; this.role = role; } public String getEmailAddress() { return emailAddress; } public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } public UserRole getRole() { return role; } public void setRole(UserRole role) { this.role = role; } /** * @return the userlist */ public Users getUserlist() { return userlist; } /** * @param userlist the userlist to set */ public void setUserlist(Users userlist) { this.userlist = userlist; } } </code></pre> <p>PersistentUser and PersistentUsers Class are the same content (but because of JDO-AppEngine Inheritance Problem two seperate classes:</p> <pre><code>@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true") @Inheritance(strategy = InheritanceStrategy.SUBCLASS_TABLE) @Version(strategy=VersionStrategy.VERSION_NUMBER) public abstract class PersistentUsers implements IPersitentObject { /** * Id * * Autogenerated String id of the Database * */ @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY) protected Key encodedKey; @Persistent protected String username; @Override public String getId() { if(encodedKey == null) return null; return KeyFactory.keyToString(encodedKey); } /*public void setId(String id) { this.encodedKey = id; }*/ /** * Helper function - get Version from DB */ @Override public Long getVersion(){ ... } /** * Helper function - will save this instance in DB */ public void persist(){ ... } /** * Helper function - will remove this instance from DB */ public void delete(){ ... } @Override public final boolean checkUsername() { ... } } </code></pre> <p>Create User Code: ... if(RequestFactoryServlet.getThreadLocalRequest().getUserPrincipal() != null){</p> <pre><code> //Create New User String email = RequestFactoryServlet.getThreadLocalRequest().getUserPrincipal().getName(); User u = UserFactory.getUser(email, UserRole.ADMINISTRATOR); //u.persist(); //Create New Userlist Users users = UserFactory.getUsers(); //Get Uids (normally empty) LinkedList&lt;String&gt; uids = (LinkedList&lt;String&gt;) users.getUserIds(); if(uids==null){ uids = new LinkedList&lt;String&gt;(); } uids.add(u.getId()); //Get DB-Userlist of current User-List LinkedList&lt;User&gt; userlist = (LinkedList&lt;User&gt;) users.getUsers(); if(userlist==null){ userlist = new LinkedList&lt;User&gt;(); } userlist.add(u); users.setUserIds(uids); users.setUsers(userlist); u.setUserlist(users); //Persit Userlist and Persist User users.persist(); this.userlistId = users.getId(); } ... </code></pre> <p>Persistence Code:</p> <pre><code>public static void persist(IPersitentObject o){ PersistenceManager pm = Pmf.get().getPersistenceManager(); try{ pm.makePersistent(o); } catch (Exception e) { e.printStackTrace(); }finally { pm.close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload