0

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.

enter image description here

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!

Dee
  • 483
  • 2
  • 11
  • 24

1 Answers1

0

If you save your bean after having deleted it, you basically recreate it. Leave out the post.save() line.

davide
  • 1,918
  • 2
  • 20
  • 30
  • Then you should take a look on the kind or request you are sending to the database. Look here: http://stackoverflow.com/questions/9719601/play-framework-2-0-and-ebean-sql-logging – davide Feb 26 '15 at 08:48
  • According to the accepted answer, in my **application.conf** file, following are been set: `db.default.logStatements=false` `logger.com.jolbox=DEBUG` – Dee Feb 27 '15 at 03:15
  • do you want me to change that `db.default.logStatements=true`? but what difference will it make? – Dee Feb 27 '15 at 03:16
  • You will see what kind of requests are sent to the database. – davide Feb 27 '15 at 05:57