title: Id of entity is different after hibernate save from oracle database with sequence autogeneration id
body: <p>Entity with id autogenerated from oracle trigger sequence.</p>
  
  <pre><code>@Entity
  @Table(name = "REPORT", schema = "WEBPORTAL")
  public class Report {
      private Integer id;
  ....
  
  
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="report_sequence")
      @SequenceGenerator(name="report_sequence", sequenceName = "report_id_seq")
      @Column(name="REPORT_ID", unique = true, nullable = false)
      public Integer getId() {
          return id;
      }
  ....
  }
  </code></pre>
  
  <p>Service</p>
  
  <pre><code>@Service("reportService")
  public class ReportServiceImpl implements ReportService {
  ....
  
      @Transactional(readOnly=false)
      public void saveOrUpdate(Report report) {
          reportDAO.saveOrUpdate(report);
      }
  }
  </code></pre>
  
  <p>DAO</p>
  
  <pre><code>@Repository
  public class ReportDAOImpl implements ReportDAO {
  ....
  
      @Override
      public Report save(Report report) {
          try {
             Session session = sessionFactory.getCurrentSession();
             session.save(report);
          } catch (Exception e) {
             logger.error("error", e);
          }
          return report;
      }
  }
  </code></pre>
  
  <p><strong>And When I call service's saveOrUpdate and then try to reach id of entity I get different value than persisted in database.</strong> Values on database with autogeneration all is ok. Any suggestions?</p>
  
  <pre><code>reportService.saveOrUpdate(report);
  System.out.println(report.getId());
  </code></pre>
  
  <p>prints: 4150
  but saved id in database is: 84</p>
  
  <p><strong>NOTE:</strong> My purpose to get Id comes from that I wanted to save childs with cascade. But foreign key on child was different in database(the values of id that I get with getId()). </p>
  
  <p>And Id generated in database is incremented by 2. EX: 80, 82, 84.</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Oracle trigger for sequence generation</p>
  
  <pre><code>CREATE OR REPLACE TRIGGER REPORT_ID_TRIG    
  BEFORE INSERT ON WEBPORTAL.REPORT  
  FOR EACH ROW   
  BEGIN   
      SELECT report_id_seq.NEXTVAL  
      INTO :new.report_id  
      FROM dual;  
  END;  
  </code></pre>