问题
I am implementing a delete option for a post! I have got model
for a post and a deletePostOnly()
java method for it to delete it PERMANENTLY using ebean delete()
function.
But the problem is that it is doing nothing and it is not deleting the post. Following is the picture of the sample post.
delete post java method
public static Result deletePostOnly(Long postId) {
//check if post can be deleted with this user
SimplePost post = SimplePost.find.byId(postId);
if(post == null) {
return badRequest();
}
UserAccount account = Secured.getCurrentUser();
if(!(post.getPostUserId().equals(account.getId()))) {
return badRequest();
}
try {
post.delete();
post.save();
} catch (Exception ex) {
ex.printStackTrace();
}
return ok("ok");
}
This is the delete()
function it is calling on
public void delete() {
Ebean.delete(this);
}
This is save()
function
@Override
public void save() {
super.save();
}
I have also tried using creating ebean query, but it is very inconsistent (it works sometimes & it doesn't sometimes.
Can anyone please tell me where I am going wrong or may be another different way to delete this post more efficiently? I couldn't think of it!
Any help/suggestions much welcomed!
回答1:
If you save your bean after having deleted it, you basically recreate it. Leave out the post.save()
line.
来源:https://stackoverflow.com/questions/28688030/play-deleting-a-post-by-id-using-ebean-permanantly