MyEclipse Forums
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
ssquire
Post subject: Scaffold 'find' method returns no DB row & test not work  PostPosted: Jan 24, 2012 - 10:30 PM
Registered Member
Registered Member


Joined: Aug 09, 2010
Posts: 89

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.
 
 View user's profile Send private message  
Reply with quote Back to top
cconway
Post subject:   PostPosted: Jan 25, 2012 - 02:16 AM



Joined: Apr 04, 2011
Posts: 196

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

Code:
Set<YourEntity> result = findYourEntity();  // <<<<< Call the find method

if (result == null || result.size()== 0) {  // <<<<< check for null or empty
    // do no result logic here
}

_________________
Cindy
MyEclipse for Spring Support
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
ssquire
Post subject:   PostPosted: Jan 25, 2012 - 01:00 PM
Registered Member
Registered Member


Joined: Aug 09, 2010
Posts: 89

Thanks Cindy!
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits