Monday, October 21, 2013

Having some Persistence Problems...

Hi,

I'm quite new at GWT and JDO Development so please excuse my little question :)

I have a User class for storing User Objects at the App Engines Datastore. 
This it was the User class looks like:



package ldk.shared.persistent;

import java.io.Serializable;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;


@PersistenceCapable
public class User implements Serializable {

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

@Persistent
private String lastName;
@Persistent
private String fName;
    @Persistent
private String eMailAdress;
@Persistent
private String passWord;

public User() {
lastName = new String();
foreName = new String();
eMailAdress = new String();
passWord = new String();
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getFName() {
return fName;
}

public void setFName(String fName) {
this.fName = fName;
}

public String geteMailAdress() {
return eMailAdress;
}

public void seteMailAdress(String eMailAdress) {
this.eMailAdress = eMailAdress;
}

public String getPassWord() {
return passWord;
}

public void setPassWord(String passWord) {
this.passWord = passWord;
}

public String getKey()
{
return encodedKey;
}

public void setKey(String key)
{
encodedKey = key;
}
}

Storing Objects of this class works fine.
Then I got a Relation Class storing 2 Instances of the User class:

package ldk.shared.persistent;

import java.io.Serializable;
import java.util.Date;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable
public class FollowerRelationships implements Serializable {

/**
*/
private static final long serialVersionUID = 1L;
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    @Extension(vendorName="datanucleus", key="gae.encoded-pk", value="true")
    private String encodedKey;

@Persistent
private User requester;
@Persistent
private User receiver;
@Persistent
private boolean approved;
@Persistent
private Date requestDate;
@Persistent
private Date approveDate;
public FollowerRelationships()
{
requester = null;
receiver = null;
requestDate = new Date();
approveDate = new Date();
}

public boolean isApproved() {
return approved;
}

public void setApproved(boolean approved) {
this.approved = approved;
}

public Date getRequestDate() {
return requestDate;
}

public void setRequestDate(Date requestDate) {
this.requestDate = requestDate;
}

public Date getApproveDate() {
return approveDate;
}

public void setApproveDate(Date approveDate) {
this.approveDate = approveDate;
}

public String getEncodedKey()
{
return encodedKey;
}

public void setEncodedKey(String encodedKey)
{
this.encodedKey = encodedKey;
}

public User getRequester()
{
return requester;
}


public void setRequester(User requester)
{
this.requester = requester;
}


public User getReceiver()
{
return receiver;
}

public void setReceiver(User receiver)
{
this.receiver = receiver;
}
}


That's the process I fail at:
1. I get 2 users from the datastorage by query - works fine
2. I create a new Instance of this relation class and set receiver and requester to these 2 users - work fine
3. Then I store the relation class to the datastore. Here comes my problem:

By storing the relationclass to the datastore 2 new user objects are stored instead of referring to my 2 users I set to this class.

How can I tell jdo to refer to my existing users instead of creating new ones?

I hope you can help me a little bit. Many thanks in advance and have a nice day

Robert



--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment