findAll() returns null
Keep
@Repository
public interface IUserDao extends CrudRepository<User, Integer> {
}
Delete UserRepository
class its implementation will be provided by spring-data-jpa.
to access:
@Autowired
private IUserDao repo;
repo.findAll();
JpaRepository .findAll method returns null values and reapeating list via postman
Thank you for your answers, it is appreciated and will give me further angles to keep in mind on future debugging.
The way I solved it in the end was updating the table column names to snake case, i.e. "FirstName" was changed to "first_name". So in hindsight, the mapping was the issue.
JPA Repository.findById() returns null but the value is exist on db
You have to change @RequestBody
to @RequestParam
. Please update your controller code as below.
@ResponseBody
@RequestMapping(value="/checkIdDuplicate", method=RequestMethod.POST)
public boolean checkIdDuplicate(@RequestParam String id) {
return memberService.isExistByUserId(id);
}
Spring JPA Query returns Null instead of List
- The normal behavior is indeed returning an empty list if no results are found. If a
List<Object>
is the return value of the method in the defined interface, the method should never returnNull
. - The problem is that a parameter is given to the method and is not used anywhere in the Query. For some reason Spring decides to return a Null in that case. Solution: remove the unused parameter or use the parameter in the Query.
JPA Repository.findByAll() returns null but everything exists in db
It seems like you are missing @Autowired
annotation in the StoreController
@Controller
public class StoragePageController {
@Autowired
private StorageService storageService;
@GET
@RequestMapping(value = "/storage")
public String openAllProductsPage(Model model) {
List<Product> productList = storageService.findAll();
model.addAttribute("productList", productList);
return "storage";
}
}
OR
The most recommended way to the dependency injection is to create a constructor with all dependencies.
@Controller
public class StoragePageController {
private final StorageService storageService;
public StoragePageController(StorageService storageService) {
this.storageService = storageService;
}
@GET
@RequestMapping(value = "/storage")
public String openAllProductsPage(Model model) {
List<Product> productList = storageService.findAll();
model.addAttribute("productList", productList);
return "storage";
}
}
Related Topics
Update Elements in a Jsonobject
Check If Url Is Https or Http Protocol
Selecting Specific Rows from Sqlite Database-Android-Sqlite Database
Getting Url Parameter in Java and Extract a Specific Text from That Url
Turkish Identity Number Verification
Spring Security 401 Unauthorized Even With Permitall
No Primary or Default Constructor Found for Interface Java.Util.List Rest API Spring Boot
Badpaddingexception Decrypting the Encrypted Data in Android
How to Compare Two Objects and Find the Fields/Properties Changed
How to Input Date Using Sendkeys in Selenium Webdriver
Removing a Column in Java from a 2D Array
Regular Expression to Find Money Value
Split Comma Separated Values in Java, Int and String
Password Validate 8 Digits, Contains Upper, Lowercase, and a Special Character
Spring Security Configuration Filter Any Requests Except a Specific Endpoint