title: ORA-02289: sequence does not exist after upgrading from hibernate 3.2 to 5.2.12
body: <p>Below is the code which was working in hibernate 3.2</p>
  
  <pre><code>public class Hibernate3Session {    
      public static void main(String[] args) throws Exception{
          Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
          sessionFactory = configuration.buildSessionFactory();
          Session session = sessionFactory.openSession();
          org.hibernate.Transaction tr = session.beginTransaction();
  
          Employee emp = new Employee();
          emp.setName("Employee1");
          emp.setContactNumber("111111");
          emp.setAddress("XYZ location");
  
          session.save(emp);
          tr.commit();
          session.close();        
  
          System.exit(0);
      }
  }
  </code></pre>
  
  <p>Below are the Employee Table</p>
  
  <pre><code>CREATE TABLE Employee
  (
    ID                     NUMBER(10)             NOT NULL,
    NAME                   VARCHAR2(50 CHAR)      NOT NULL,
    CONTACT_NUMBER         VARCHAR2(50 CHAR),
    ADDRESS                VARCHAR2(50 CHAR),
    PRIMARY KEY (ID)
  );
  
  
  
  and the sequences used for the same
  CREATE SEQUENCE SEQ_EMPLOYEE_ID  
                                  MINVALUE 1 
                                  NOMAXVALUE 
                                  INCREMENT BY 1 START WITH 1 NOCACHE  NOCYCLE ;
  </code></pre>
  
  <p>Below is the hibernate.cfg.xml file</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="connection.driver_class"&gt;oracle.jdbc.OracleDriver&lt;/property&gt;
          &lt;property name="connection.url"&gt;jdbc:oracle:thin:@localhost:1521:dbname&lt;/property&gt;
          &lt;property name="connection.username"&gt;SYSTEM&lt;/property&gt;
          &lt;property name="connection.password"&gt;systempassword&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.OracleDialect&lt;/property&gt;                
          &lt;property name="hibernate.connection.autocommit"&gt;true&lt;/property&gt;        
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
          &lt;mapping resource="Employee.hbm.xml" /&gt;
  
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>Below are the corresponding Employee.hbm.xml</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt;
  
  &lt;hibernate-mapping&gt;
      &lt;class name="Employee" table="EMPLOYEE" &gt;
          &lt;id name="id" type="long" &gt;
              &lt;column name="ID" /&gt;
              &lt;generator class="sequence"&gt;
                  &lt;param name="sequence"&gt;SEQ_EMPLOYEE_ID&lt;/param&gt;
              &lt;/generator&gt;
          &lt;/id&gt;
          &lt;property name="name" type="string"&gt;
              &lt;column name="NAME" length="50" not-null="true" /&gt;
          &lt;/property&gt;
          &lt;property name="contactNumber" type="string"&gt;
              &lt;column name="CONTACT_NUMBER" length="50" /&gt;
          &lt;/property&gt;
          &lt;property name="address" type="string"&gt;
              &lt;column name="ADDRESS" length="50" /&gt;
          &lt;/property&gt;
      &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>Below are the corresponding POJO classes for the same</p>
  
  <pre><code>public class Employee {
  
      private Long id;
      private String name;
      private String contactNumber;
      private String address;
  
      public Long getId() {
          return id;
      }
      public void setId(Long id) {
          this.id = id;
      }
  
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
  
      public String getContactNumber() {
          return contactNumber;
      }
      public void setContactNumber(String contactNumber) {
          this.contactNumber = contactNumber;
      }
  
      public String getAddress() {
          return address;
      }
      public void setAddress(String address) {
          this.address = address;
      }
      @Override
      public int hashCode() {
          final int prime = 31;
          int result = 1;
          result = prime * result + ((address == null) ? 0 : address.hashCode());
          result = prime * result + ((contactNumber == null) ? 0 : contactNumber.hashCode());
          result = prime * result + ((id == null) ? 0 : id.hashCode());
          result = prime * result + ((name == null) ? 0 : name.hashCode());
          return result;
      }
      @Override
      public boolean equals(Object obj) {
          if (this == obj)
              return true;
          if (obj == null)
              return false;
          if (getClass() != obj.getClass())
              return false;
          Employee other = (Employee) obj;
          if (address == null) {
              if (other.address != null)
                  return false;
          } else if (!address.equals(other.address))
              return false;
          if (contactNumber == null) {
              if (other.contactNumber != null)
                  return false;
          } else if (!contactNumber.equals(other.contactNumber))
              return false;
          if (id == null) {
              if (other.id != null)
                  return false;
          } else if (!id.equals(other.id))
              return false;
          if (name == null) {
              if (other.name != null)
                  return false;
          } else if (!name.equals(other.name))
              return false;
          return true;
      }   
  }
  </code></pre>
  
  <p>The code using for hibernate 5.2 final version is as below</p>
  
  <pre><code>public class Hibernate5vSession {   
      public static void main(String[] args) throws Exception{
          SessionFactory sessionFactory = null;
          StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder().configure("hibernate.cfg.xml");
          MetadataSources sources = new MetadataSources(registryBuilder.build());
          //sources.addResource("EmployeeRegistration.hbm.xml");
          Metadata metaData = sources.getMetadataBuilder().build();       
          sessionFactory = metaData.getSessionFactoryBuilder().build();
  
          Session session = sessionFactory.openSession();
          org.hibernate.Transaction tr = session.beginTransaction();
  
          Employee emp = new Employee();
          emp.setName("Employee1");
          emp.setContactNumber("111111");
          emp.setAddress("XYZ location");
  
          session.save(emp);
          tr.commit();
          session.close();        
  
          System.exit(0);
      }
  }
  </code></pre>
  
  <p>Also changed the Dialect below:</p>
  
  <pre><code>&lt;property name="dialect"&gt;org.hibernate.dialect.Oracle10gDialect&lt;/property&gt;
  </code></pre>
  
  <p>Getting below error</p>
  
  <p>Hibernate: select hibernate_sequence.nextval from dual
  Mar 06, 2018 7:56:02 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  WARN: SQL Error: 2289, SQLState: 42000
  Mar 06, 2018 7:56:02 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  ERROR: ORA-02289: sequence does not exist</p>
  
  <pre><code>Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not extract ResultSet
      at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
      at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
      at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:69)
      at org.hibernate.id.enhanced.SequenceStructure$1.getNextValue(SequenceStructure.java:95)
      at org.hibernate.id.enhanced.NoopOptimizer.generate(NoopOptimizer.java:40)
      at org.hibernate.id.enhanced.SequenceStyleGenerator.generate(SequenceStyleGenerator.java:452)
      at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:105)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
      at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
      at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
      at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
      at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:691)
      at org.hibernate.internal.SessionImpl.save(SessionImpl.java:683)
      at org.hibernate.internal.SessionImpl.save(SessionImpl.java:678)
      at HibernateSessionFactory.main(HibernateSessionFactory.java:62)
  Caused by: java.sql.SQLException: ORA-02289: sequence does not exist
  
      at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:125)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:305)
      at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
      at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:626)
      at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:185)
      at oracle.jdbc.driver.T4CPreparedStatement.execute_for_describe(T4CPreparedStatement.java:503)
      at oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement.java:951)
      at oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedStatement.java:535)
      at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1046)
      at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:2905)
      at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:2946)
      at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:60)
      ... 13 more
  </code></pre>
  
  <p><strong>Note:</strong> Have verified the Privileges at Oracle. The table is present in admin user System schema and the same is used for credentials. </p>
  
  <p>I have obtained the SessionFactory as mentioned <a href="https://docs.jboss.org/hibernate/orm/5.2/userguide/html_single/Hibernate_User_Guide.html" rel="nofollow noreferrer">here</a>.</p>
  
  <p>In console it looks from hibernate sequence rather than Oracle</p>
  
  <pre><code>Hibernate: select hibernate_sequence.nextval from dual
  Mar 06, 2018 10:26:47 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
  WARN: SQL Error: 2289, SQLState: 42000
  </code></pre>
  
  <p>why this is not working when i upgrade the hibernate version to 5.2.12</p>
  
  <p>Any help in this?.</p>