Gae - One-to-one Relationship Delete Giving Error
I am using Eclipse to develop Android with Google App engine. I have 3 entities User->UserDetails->UserPassword. Each one has a @OneToOne relationship to the other thru USER_
Solution 1:
After working for sometime with JPA/JDO + google endpoints, I gave up (there were multiple issues). JPA/JDO is more for RDBMS but Google datasore is more like a HashMap. I decided to try Objectify which is designed specifically for Google datastore. My experience with it has been better. You need to read the solution below along with the discussion at: GAE+Objectify - Parameterized type com.googlecode.objectify.Ref not supported to get a better understanding.
In order to delete the User, UserDetails and Password in Objectify, below is the code.
@ApiMethod(name = "deleteAllUsers", path="delete_all_users")
publicvoiddeletAllUsers(){
log.info("UserEndpoint.deletAllUsers...");
List<User> users = ofy().load().type(User.class).list();
User user = null;
try{
for(int i=0; i< users.size(); i++){
user = users.get(i);
UserDetails userDetails = user.getUserDetails();
UserPassword userPassword = user.getUserPassword();
ofy().delete().entity(userDetails).now();
ofy().delete().entity(userPassword).now();
ofy().delete().entity(user).now();
}
}
catch(Exception e){
log.info("AccountEndpoint.deleteAllUsers()...exception="+e.getMessage());
}
log.info("AccountEndpoint.deletAllUsers...all users deleted");
}
Post a Comment for "Gae - One-to-one Relationship Delete Giving Error"