Null data in an entity, but not null, when it is sent. How is it possible?

When I get an entity "Product" in the controller, I have all the null data.

@GetMapping("/admin/product/delete")
public ModelAndView showProductDeletePage(
        @RequestParam String productId
){
    Long longId = Long.parseLong(productId);
    Product product = productService.getProductById(longId);

    ModelAndView modelAndView = new ModelAndView("/admin/product/delete");
    modelAndView.addObject("product", product);

    return modelAndView;
}

enter image description here

But, in the string

    modelAndView.addObject("product", product);

I send a product to the page.

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title th:text="'Delete ' + ${product.getProductName()}">Delete</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">

</head>
<body>
<div class="w3-container">
    <form th:action="@{'/admin/product/delete?productId=' + ${product.getId()}}" method="post">
    <h2>Delete product</h2>
    <p>If you submit, product will be deleted irrevocably</p>

    <div th:text = "${product.getProductName()}" class="w3-panel w3-card-4"><p>w3-card-4</p>
    </div>
        <a href="/" class="w3-button w3-green">Cancel</a>
        <input class="w3-button w3-red" type="submit" value="Delete"/>
    </form>
</div>

</body>
</html>

And, for example, in the strings

    <div th:text = "${product.getProductName()}" class="w3-panel w3-card-4"><p>w3-card-4</p>
<form th:action="@{'/admin/product/delete?productId=' + ${product.getId()}}" method="post">

my app has not a problem and returns to the screen correctly data.

How is it possible?

An issue in it, that I cannot use the entity in the other cases. And in general - how is it possible??

1 answer

  • answered 2018-07-12 07:23 Abubakar Iftikhar

    Possible reasons are:

    • You may have different connection strings.
    • Your web application is not in running state.
    • You have cached data.

    Its not possible in the way you are trying to describe the issue, add debugger/breakpoints to narrow down your issue.