I have a class naming User and this includes 2 address references
(billingAddress and shippinAddress) of type Adddress. Im unable to
make the one-to-one relation between these classes. My problem is,
when I save User, both addresses get saved(which is right). But when
I try to getUserById, I get billingAddress and shippingAddress having
same data. my code is as follows:
@PersistenceCapable(identityType = IdentityType.APPLICATION,
detachable = "true")
public class MyUser {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
Long id;
@Persistent
private String emailId;
@Persistent
private String password;
@Persistent
private String firstName;
@Persistent
private String lastName;
@Persistent(dependent="true", column="billingAddress")
private Address billingAddress;
@Persistent(dependent="true", column="shippingAddress")
private Address shippingAddress;
@Persistent
private Role role;
@Persistent
private String phoneNumber;
--------------------------------------------------------------------------
@PersistenceCapable
public class Address {
@PrimaryKey
@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value
= "true")
private String id;
@Persistent
private String houseNo;
@Persistent
private String buildingNo;
@Persistent
private String streetNo;
@Persistent
private String line1;
@Persistent
private String line2;
@Persistent
private String zipCode;
@Persistent
private String city;
@Persistent
private String state;
@Persistent
private String country;
@Persistent
private String region;
@Persistent
private boolean isDefault;
--------------------------------------------------------------------------
@Transactional
public MyUser checkLogin(String emailId, String password) {
MyUser existingUser = null;
try {
pm = PMF.get().getPersistenceManager();
Query query = pm.newQuery(MyUser.class);
query.setFilter("emailId == '" + emailId + "' &&
password == '"
+ password + "'");
query.setUnique(true);
existingUser = (MyUser) query.execute();
log.info("Logged in UserDetails: >>> " +existingUser);
return existingUser;
} catch (Exception e) {
log.severe("Exception caught in checkLogin: " + e);
return existingUser;
}
}
Can somebody help me in understanding the mappings.
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.