title: org.hibernate.id.enhanced.TableStructure - could not read a hi value
body: <p>I work with a <code>Spring MVC/ Hibernate</code> app and re-started it after a while again to work on. This time I get the following errors, </p>
  
  <pre><code>javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: could not read a hi value - you need to populate the table: hibernate_sequence
      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
      at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
      at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:787)
      at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:765)
      at mobi.puut.database.WalletInfoDaoHibernate.create(WalletInfoDaoHibernate.java:65)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
      at com.sun.proxy.$Proxy39.create(Unknown Source)
      at mobi.puut.services.WalletServiceImpl.createWalletInfo(WalletServiceImpl.java:279)
      at mobi.puut.services.WalletServiceImpl.lambda$generateAddress$0(WalletServiceImpl.java:104)
      at mobi.puut.controllers.WalletManager$1.lambda$onSetupCompleted$0(WalletManager.java:105)
      at java.lang.Iterable.forEach(Iterable.java:75)
      at java.util.Collections$SynchronizedCollection.forEach(Collections.java:2062)
      at mobi.puut.controllers.WalletManager$1.onSetupCompleted(WalletManager.java:105)
      at org.bitcoinj.kits.WalletAppKit.startUp(WalletAppKit.java:325)
      at com.google.common.util.concurrent.AbstractIdleService$2$1.run(AbstractIdleService.java:54)
      at com.google.common.util.concurrent.Callables$3.run(Callables.java:95)
      at java.lang.Thread.run(Thread.java:748)
  Caused by: org.hibernate.id.IdentifierGenerationException: could not read a hi value - you need to populate the table: hibernate_sequence
      at org.hibernate.id.enhanced.TableStructure$1$1.execute(TableStructure.java:142)
      at org.hibernate.id.enhanced.TableStructure$1$1.execute(TableStructure.java:126)
      at org.hibernate.jdbc.WorkExecutor.executeReturningWork(WorkExecutor.java:55)
      at org.hibernate.jdbc.AbstractReturningWork.accept(AbstractReturningWork.java:34)
      at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcIsolationDelegate.delegateWork(JdbcIsolationDelegate.java:57)
      at org.hibernate.id.enhanced.TableStructure$1.getNextValue(TableStructure.java:125)
      at org.hibernate.id.enhanced.NoopOptimizer.generate(NoopOptimizer.java:40)
      at org.hibernate.id.enhanced.SequenceStyleGenerator.generate(SequenceStyleGenerator.java:432)
      at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:105)
      at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189)
      at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)
      at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)
      at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:780)
      ... 23 more
  org.hibernate.id.enhanced.TableStructure: 08/15/2017 13:48:27 - could not read a hi value - you need to populate the table: hibernate_sequence
  Exception in thread " STARTING" java.lang.IllegalStateException: org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl@5e9059bd is closed
      at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.errorIfClosed(AbstractLogicalConnectionImplementor.java:37)
      at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:144)
      at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getConnectionForTransactionManagement(LogicalConnectionManagedImpl.java:263)
      at org.hibernate.resource.jdbc.internal.AbstractLogicalConnectionImplementor.rollback(AbstractLogicalConnectionImplementor.java:116)
      at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.rollback(JdbcResourceLocalTransactionCoordinatorImpl.java:239)
      at org.hibernate.engine.transaction.internal.TransactionImpl.rollback(TransactionImpl.java:100)
      at mobi.puut.database.WalletInfoDaoHibernate.create(WalletInfoDaoHibernate.java:71)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
      at com.sun.proxy.$Proxy39.create(Unknown Source)
      at mobi.puut.services.WalletServiceImpl.createWalletInfo(WalletServiceImpl.java:279)
      at mobi.puut.services.WalletServiceImpl.lambda$generateAddress$0(WalletServiceImpl.java:104)
      at mobi.puut.controllers.WalletManager$1.lambda$onSetupCompleted$0(WalletManager.java:105)
      at java.lang.Iterable.forEach(Iterable.java:75)
      at java.util.Collections$SynchronizedCollection.forEach(Collections.java:2062)
      at mobi.puut.controllers.WalletManager$1.onSetupCompleted(WalletManager.java:105)
      at org.bitcoinj.kits.WalletAppKit.startUp(WalletAppKit.java:325)
      at com.google.common.util.concurrent.AbstractIdleService$2$1.run(AbstractIdleService.java:54)
      at com.google.common.util.concurrent.Callables$3.run(Callables.java:95)
      at java.lang.Thread.run(Thread.java:748)
  </code></pre>
  
  <p>I have few tables in the <code>Database</code> and the <code>hibernate_sequence</code> table is provided below, </p>
  
  <p><a href="https://i.stack.imgur.com/NEd8w.png" rel="noreferrer"><img src="https://i.stack.imgur.com/NEd8w.png" alt="enter image description here"></a></p>
  
  <p>I have seen someone is suggested in the forum to fill the <code>hibernate_sequence</code> table as following and I have done this which doesn't solve it issue. </p>
  
  <pre><code>Insert into wallet.hibernate_sequence(next_val) values(0)
  </code></pre>
  
  <p>I use <code>Java annotation based</code> config and the database connection is provided below, </p>
  
  <pre><code>    @Bean
      public DataSource dataSource() {
  
          DriverManagerDataSource dataSource = new DriverManagerDataSource();
          dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
  
          // dataSource.setUrl("jdbc:mysql://localhost:3306/wallet?createDatabaseIfNotExist=true");
          dataSource.setUrl("jdbc:mysql://localhost:3306/wallet");
          dataSource.setUsername("testuser");
          dataSource.setPassword("testpassword");
  
          return dataSource;
      }
  
      Properties hibernateProperties() {
  
          Properties properties = new Properties();
  //        properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
          properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
          properties.setProperty("hibernate.id.new_generator_mappings", "false");
          return properties;
      }
  </code></pre>
  
  <p>Here is the <code>POM</code> I use for the app, </p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.puut.wallet&lt;/groupId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;artifactId&gt;BitcoinWalletApp&lt;/artifactId&gt;
      &lt;name&gt;Bitcoin Wallet&lt;/name&gt;
  
      &lt;build&gt;
          &lt;resources&gt;
              &lt;resource&gt;
                  &lt;directory&gt;src/main/resources&lt;/directory&gt;
                  &lt;filtering&gt;true&lt;/filtering&gt;
              &lt;/resource&gt;
              &lt;resource&gt;
                  &lt;directory&gt;src/main/java&lt;/directory&gt;
              &lt;/resource&gt;
          &lt;/resources&gt;
      &lt;/build&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.bitcoinj&lt;/groupId&gt;
          &lt;artifactId&gt;bitcoinj-parent&lt;/artifactId&gt;
          &lt;version&gt;0.14.4&lt;/version&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;spring.version&gt;4.3.10.RELEASE&lt;/spring.version&gt;
          &lt;spring.security.version&gt;4.2.3.RELEASE&lt;/spring.security.version&gt;
      &lt;/properties&gt;
  
  
      &lt;dependencies&gt;
  
          &lt;!--crypto-currencies dependencies--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.bitcoinj&lt;/groupId&gt;
              &lt;artifactId&gt;bitcoinj-core&lt;/artifactId&gt;
              &lt;version&gt;${project.parent.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
          &lt;!--spring dependencies--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-beans&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-jdbc&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-test&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
              &lt;version&gt;${spring.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;!--spring security dependencies--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
              &lt;version&gt;${spring.security.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
              &lt;version&gt;${spring.security.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
              &lt;version&gt;${spring.security.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-taglibs&lt;/artifactId&gt;
              &lt;version&gt;${spring.security.version}&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;!--web API dependencies--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.validation&lt;/groupId&gt;
              &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
              &lt;version&gt;RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-validator&lt;/groupId&gt;
              &lt;artifactId&gt;commons-validator&lt;/artifactId&gt;
              &lt;version&gt;1.6&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.guava&lt;/groupId&gt;
              &lt;artifactId&gt;guava&lt;/artifactId&gt;
              &lt;version&gt;18.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
              &lt;version&gt;1.7.20&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.glxn&lt;/groupId&gt;
              &lt;artifactId&gt;qrgen&lt;/artifactId&gt;
              &lt;version&gt;1.3&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;3.1.0&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;jstl&lt;/artifactId&gt;
              &lt;version&gt;1.2&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;!--testing and database dependencies incl. hibernate--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;4.12&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-dbcp&lt;/groupId&gt;
              &lt;artifactId&gt;commons-dbcp&lt;/artifactId&gt;
              &lt;version&gt;1.4&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;version&gt;6.0.6&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
              &lt;version&gt;5.2.10.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
              &lt;version&gt;5.4.1.Final&lt;/version&gt;
          &lt;/dependency&gt;
  
  
          &lt;!-- Jackson dependencies--&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-core&lt;/artifactId&gt;
              &lt;version&gt;RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.fasterxml.jackson.core&lt;/groupId&gt;
              &lt;artifactId&gt;jackson-databind&lt;/artifactId&gt;
              &lt;version&gt;RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.ws.rs&lt;/groupId&gt;
              &lt;artifactId&gt;jsr311-api&lt;/artifactId&gt;
              &lt;version&gt;1.1.1&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>Here is the <code>WalletInfo</code> pojo, </p>
  
  <pre><code>@Entity
  @Table(name = "wallet_info")
  public class WalletInfo {
  
      @Id
      @Column(name = "id")
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      @NotNull
      @Column(name = "name")
      private String name;
  
      @NotNull
      @Column(name = "address")
      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 getAddress() {
          return address;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  }
  </code></pre>
  
  <p>Whats the issue here and how to solve it?</p>