title: How to calculate the outcome of difference between two fields from hibernate and show it on a jsp?
body: <p>I am making a simple CRUD app, using spring mvc, hibernate and mySQL.</p>
  
  <p>I have a single table in mySQL:</p>
  
  <pre><code>CREATE TABLE `product` (
      `id` INT NOT NULL AUTO_INCREMENT,
      `product_name` VARCHAR(45) DEFAULT NULL,
      `quantity_needed` INT DEFAULT NULL,
      `status` INT DEFAULT NULL,
       PRIMARY KEY (`id`)
  )ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
  </code></pre>
  
  <p>I have the basics fixes - listing all of the elements on a JSP, adding a new element, updating and deleting.
  I want to also show a separate list with just the products, where the status value &lt; quantity_needed <strong>with the difference being shown</strong>. I created the code to show just the list(without anything else). Below is a part of my <em>productDAOImpl</em>:</p>
  
  <pre><code>@Transactional
  @Override
  public List&lt;Product&gt; buyList() {
  
      // get the current hibernate session
      Session currentSession = sessionFactory.getCurrentSession();
  
      // query the database to find the requested items
      Query&lt;Product&gt; theQuery = currentSession.createQuery("from Product p where p.status&lt;p.quantityNeeded");
  
      // get the result list
      List&lt;Product&gt; buyList = theQuery.getResultList();
  
      return buyList;
  }
  </code></pre>
  
  <p>and a the <em>controller</em>:</p>
  
  <pre><code>@GetMapping("/buy")
  public String buyList(Model theModel) {
  
      // get the requested list of items to be bought
      List&lt;Product&gt; theProduct = productDAO.buyList();
  
      // add them to the page
      theModel.addAttribute("products", theProduct);
  
      return "buy-list";
  }
  </code></pre>
  
  <p>part of my <em>JSP</em>:</p>
  
  <pre><code>&lt;c:forEach var="tempProduct" items="${products}"&gt;
      &lt;tr&gt;
          &lt;td&gt;${tempProduct.productName}&lt;/td&gt;
          &lt;td&gt;{tempProduct.difference}&lt;/td&gt;
      &lt;/tr&gt;
  </code></pre>
  
  <p>In my product entity I created a new field <em>difference</em></p>
  
  <pre><code>// field for quantityNeeded-status value
  @Transient
  private int difference;
  public int getDifference(Integer quantityNeeded,Integer status) {
  
      difference=quantityNeeded-status;
  
      return difference;
  }
  </code></pre>
  
  <p>As mentioned above, the list I am showing should also have a new parameter, which will be calculated(as a difference of 2 ints from the database).This value will be shown on the page.</p>
  
  <p>How can I do this? </p>