title: how to stop HQL hibernate insert multiple data inserted?
body: <p>Implementation: HQL hibernate. Im trying to save 1 data but what happen is its saving <code>many data</code> the only i stop it is by <code>result &gt; 1 to NullPointerException</code>. I already put some  <code>session.close()</code> still saving multiple.</p>
  <p>Hibernate has <code>save</code> but where not gonna use that.</p>
  <pre><code>@Override
      public Product save(Product product) {
          Transaction transaction = null;
    
          Session session = HibernateUtil.getSessionFactory().openSession();
  
              transaction = session.beginTransaction();
  
              String hql = &quot;INSERT INTO Product  ( productname, productbrand, productprice, productdescription, productquantity, productexpirationdate) &quot; +
                  &quot;SELECT   productname, productbrand, productprice, productdescription, productquantity, productexpirationdate FROM Product &quot;;
              Query query = session.createQuery(hql);
              Integer result =  query.executeUpdate();
          
              transaction.commit();
              session.close();
  
               if (result == 0 ||result == null  ) {
                     
                  throw new NullPointerException();
              }
              
             // if (result &gt; 1 || result &gt;= 0 ||result == null  ) {
             //      
             ///  throw new NullPointerException();
              //}
              
  
          return product;
      }
  
  </code></pre>
  <p>Example in data in database insert 1 data then suddenly  inserting multiple data.
  how to stop this?</p>
  <pre><code>'1', 'Hello1234', 'Hello', '2022-10-27 00:00:00', 'Hello1234', '1.4', '10', NULL
  '2', 'Hello1234', 'Hello', '2022-10-27 00:00:00', 'Hello1234', '1.4', '10', NULL
  '3', 'Hello1234', 'Hello', '2022-10-27 00:00:00', 'Hello1234', '1.4', '10', NULL
  '4', 'Hello1234', 'Hello', '2022-10-27 00:00:00', 'Hello1234', '1.4', '10', NULL
  
  </code></pre>
  <p>Database query</p>
  <pre><code>CREATE TABLE `tb_product` (
    `purchase_item` int NOT NULL AUTO_INCREMENT,
    `productbrand` varchar(255) NOT NULL,
    `productdescription` varchar(255) NOT NULL,
    `productexpirationdate` datetime NOT NULL,
    `productname` varchar(255) NOT NULL,
    `productprice` double NOT NULL,
    `productquantity` int NOT NULL,
    PRIMARY KEY (`purchase_item`),
    UNIQUE KEY `purchase_item_UNIQUE` (`purchase_item`)
  ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
  
  </code></pre>