facebook

Scaffold ‘find’ method returns no DB row & test not work

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #322638 Reply

    ssquire
    Member

    I have a Spring Scaffolded “find” method that correctly does not return a row from my database. If I print the contents of the pointer to the “find” method using “System.out.println(“The contents of the Set are:”+ ptr);” what is printed is the following: “The contents of the Set are: [ ]” (with no space in between, I did that for clarity). When I compare using “if (ptr.equal(“[ ]”)…” it never goes inside the “if” statement. When I compare using “if (ptr.equal(null)…” it never goes inside the “if” statement. Or even “if (ptr.equal(“”)…” it never goes inside the “if” statement.

    How do I make the check to test if row information was not returned from the Scaffolded “find” method? It seems that even when I use the exact characters printed in my debug statement, that doesn’t work.

    #322645 Reply

    cconway
    Member

    It sounds like the find method is returning an empty set. The way to check for empty set is this:

    Set<YourEntity> result = findYourEntity();  // <<<<< Call the find method
    
    if (result == null || result.size()== 0) {  // <<<<< check for null or empty
        // do no result logic here
    }
    #322673 Reply

    ssquire
    Member

    Thanks Cindy!

Viewing 3 posts - 1 through 3 (of 3 total)
Reply To: Scaffold ‘find’ method returns no DB row & test not work

You must be logged in to post in the forum log in