The value in database can be sometimes NULL and sometimes not. How can I retrieve it?
This is my try which makes me suprised:
@Repository
public interface AddressRepo extends JpaRepository<Address, Long>{
@Query("select count(a) > 0 from Address a where a.street = :street")
boolean testtest(@Param("street") String street);
}
test OK:
// given
address = new Address("WIELKA WARSZAAAWA", "Bokserska", "xxx", "50-500");
// when
addressRepo.save(address);
// then
assertTrue(addressRepo.testtest("Bokserska")); // OK
test fails:
// given
address = new Address("WIELKA WARSZAAAWA", null, "xxx", "50-500");
// when
addressRepo.save(address);
// then
assertTrue(addressRepo.testtest(null)); // cuz false!
where a.street is null.streetis not null won't work!if(street ==null) {addressRepo.testtest2} ... if(city == null) {..} if(street == null && city == null) {...}etc.