title: Hibernate Insert if record does not exist
body: <p>How can I do this with Hibernate - If record does not exists insert it.</p>
  
  <p>I have the following columns</p>
  
  <p>Id (Primary Key),
  Ticker Symbol,
  Ticker Name,
  Industry,
  Sector,
  LastUpdate</p>
  
  <p>I would like to check the records at Ticker Symbol Column if the string exist don't do anything if it does not exist then insert a new row with Id, Ticker Symbol, Ticker Name, Industry, Sector and Update Date (today's date). </p>
  
  <p>I have gone as far as creating a new Table with the code below. </p>
  
  <pre><code>//Hibernate Create a Session Factory    
   SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();         
   for (int i = 0; i &lt; Bloomberg.getTickerSymbol().size(); i++){
  
              //Hibernate to store Stock Tickers Data     
          tickerInfo.setTickerSymbol(Bloomberg.getTickerSymbol().get(i)); //Symbol
          tickerInfo.setTickerName(Bloomberg.getTickerName().get(i)); //Name
          tickerInfo.setTickerSector(Bloomberg.getTickerSector().get(i)); //Sector
          tickerInfo.setTickerIndustry(Bloomberg.getTickerIndustry().get(i)); //Industry
          tickerInfo.setTickerLastUpdate(Calendar.getInstance().getTime()); //Update Date
  
          org.hibernate.Session session = sessionFactory.openSession();
          session.beginTransaction();
          session.saveOrUpdate(tickerInfo);
          session.getTransaction().commit();
          session.close();
  }
  </code></pre>