-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: HIbernate 5: ORA-02289: sequence does not exist
PostPosted: Tue Jun 21, 2016 6:05 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
I am upgrading Hibernate 3->5.1 and getting below exception. I also upgraded Spring 3->4 but it may not be related.
Quote:
> Caused by: org.hibernate.exception.SQLGrammarException: could not
> extract ResultSet
> at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63)
> 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:79)
> at org.hibernate.id.enhanced.SequenceStructure$1.getNextValue(SequenceStructure.java:96)
> at org.hibernate.id.enhanced.NoopOptimizer.generate(NoopOptimizer.java:40)
> at org.hibernate.id.enhanced.SequenceStyleGenerator.generate(SequenceStyleGenerator.java:412)
> 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.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
> at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:97)
> at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
> at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:651)
> at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:643)
> at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:638)
> at org.springframework.orm.hibernate5.HibernateTemplate$16.doInHibernate(HibernateTemplate.java:684)
> at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:341)
> ... 91 more Caused by: java.sql.SQLSyntaxErrorException: ORA-02289: sequence does not exist
>
> at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
> at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
> at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
> at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
> at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
> at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
> at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
> at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:884)
> at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167)
> at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1289)
> at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584)
> at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628)
> at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1



during model save / creation. Mappings are left like in Hibernate 3, all of them are in hbm.xml files

Code:
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
    <hibernate-mapping default-lazy="false">
       <class name="MyModel"
          table="MY_MODEL" dynamic-update="true">
   
          <id name="id" type="long" access="property">
             <column name="ID" precision="19" scale="0" />
             <generator class="sequence">
                <param name="sequence">MY_SEQ</param>
             </generator>
          </id>
          <version name="version" type="integer">
             <column name="VERSION" precision="10" scale="0" />
          </version>
   
    (...)


Debugging Hibernate classes gives me a hint that, the sequence that he wants to use is
Code:
`hibernate_sequence.nextval`


instead of
Code:
`MY_SEQ`



Debugging AbstractEntityPersister and entityMetamodel.getIdentifierProperty()

I am getting different results:

Hibernate 3 (Hibernate uses SequenceGenerator, which works fine but is deprecated in Hibernate 5):
Code:
result = {IdentifierProperty@22370} "Property(id:long)"
virtual = false
embedded = false
unsavedValue = {IdentifierValue@22373} "identifier unsaved-value: null"
identifierGenerator = {SequenceGenerator@22333}
  sequenceName = "MY_SEQ"
  parameters = null
  identifierType = {LongType@22345}
  sql = "select MY_SEQ.nextval from dual"
identifierAssignedByInsert = false
hasIdentifierMapper = false
name = "id"
node = "id"
type = {LongType@22345}


Hibernate 5:

Code:
result = {IdentifierProperty@23725} "IdentifierAttribute(id)"
virtual = false
embedded = false
unsavedValue = {IdentifierValue@23728} "identifier unsaved-value: null"
identifierGenerator = {SequenceStyleGenerator@23665}
  databaseStructure = {SequenceStructure@23671}
   logicalQualifiedSequenceName = {QualifiedNameParser$NameParts@23737} "hibernate_sequence"
   initialValue = 1
   incrementSize = 1
   numberType = {Class@23293} "class java.lang.Long"
   sequenceName = "hibernate_sequence"
   sql = "select hibernate_sequence.nextval from dual"
   applyIncrementSizeToSourceValues = false
   accessCounter = 1
  optimizer = {NoopOptimizer@23664}
  identifierType = {LongType@23730}
identifierAssignedByInsert = false
hasIdentifierMapper = false
attributeName = "id"
attributeType = {LongType@23730}


Top
 Profile  
 
 Post subject: Re: HIbernate 5: ORA-02289: sequence does not exist
PostPosted: Tue Jun 21, 2016 8:13 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
By default, Hibernate 5 switches to the enhanced identifier generators.

Because you have already generated identifiers using the old strategies, you need to explicitly set that you don't want to use the enhanced identifiers:

Code:
<property
    name="hibernate.id.new_generator_mappings"
    value="false"/>


Top
 Profile  
 
 Post subject: Re: HIbernate 5: ORA-02289: sequence does not exist
PostPosted: Tue Jun 21, 2016 8:47 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
Thanks! It would be great however I am trying like this with no results:
Code:
<bean id="hibernateProperties"
      class="org.springframework.beans.factory.config.PropertiesFactoryBean"
      abstract="false" lazy-init="default" autowire="default">
   
      <property name="properties">
         <props>
            <prop key="hibernate.id.new_generator_mappings">false</prop>
            <prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
            <prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>
            <prop key="hibernate.cache.use_second_level_cache">false</prop>
            <prop key="hibernate.cache.use_query_cache">false</prop>
            <prop key="hibernate.jdbc.fetch_size">11</prop>
         </props>
      </property>
   </bean>


Code:
<bean id="sessionFactory"
      class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
               <property name="dataSource">
         <ref bean="${dataSource}" />
      </property>
      
      <property name="mappingLocations" ref="hbmMappingLocationss"/>

      <property name="hibernateProperties">
         <ref bean="hibernateProperties" />
      </property>
         
   </bean>


Moreover debugging MetadataBuilderImpl I see
Code:
useNewIdentifierGenerators = false
:

Code:
sourceProcessOrdering = resolveInitialSourceProcessOrdering( configService );

         final boolean useNewIdentifierGenerators = configService.getSetting(
               AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS,
               StandardConverters.BOOLEAN,
               true
         );
         if ( useNewIdentifierGenerators ) {
            idGenerationTypeInterpreter.disableLegacyFallback();
         }
         else {
            idGenerationTypeInterpreter.enableLegacyFallback();
         }


Top
 Profile  
 
 Post subject: Re: HIbernate 5: ORA-02289: sequence does not exist
PostPosted: Tue Jun 21, 2016 9:43 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Add a breakpoint and see if it executes this logic:

Code:
idGenerationTypeInterpreter.enableLegacyFallback();


Does it go through that setting?


Top
 Profile  
 
 Post subject: Re: HIbernate 5: ORA-02289: sequence does not exist
PostPosted: Tue Jun 21, 2016 10:04 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
Yes it does invoke it.

Generally I see those values:

Code:
hibernateProperties = {Properties@7243}  size = 8
0 = {Hashtable$Entry@7274} "hibernate.id.new_generator_mappings" -> "false"
1 = {Hashtable$Entry@7275} "hibernate.dialect" -> "org.hibernate.dialect.Oracle10gDialectt"
2 = {Hashtable$Entry@7276} "hibernate.show_sql" -> "false"
3 = {Hashtable$Entry@7277} "hibernate.cache.use_second_level_cache" -> "false"
4 = {Hashtable$Entry@7278} "hibernate.bytecode.use_reflection_optimizer" -> "false"
5 = {Hashtable$Entry@7279} "hibernate.cache.use_query_cache" -> "false"
6 = {Hashtable$Entry@7280} "hibernate.hbm2ddl.auto" ->
7 = {Hashtable$Entry@7281} "hibernate.jdbc.fetch_size" -> "11"


and
Code:
idGenerationTypeInterpreter = {IdGeneratorInterpreterImpl@8651}
fallbackInterpreter = {IdGeneratorInterpreterImpl$LegacyFallbackInterpreter@8653}
  No fields to display
delegates = null


I am also checking SimpleValue.public IdentifierGenerator createIdentifierGenerator(
Code:
identifierGeneratorProperties = {Properties@9609}  size = 2
0 = {Hashtable$Entry@9614} "identifier_normalizer" ->
1 = {Hashtable$Entry@9615} "sequence" -> "MY_SEQ"

identifierGeneratorStrategy = "sequence"
identifierGenerator = null

identifierGeneratorFactory = {DefaultIdentifierGeneratorFactory@9541} 

identifierGenerator = identifierGeneratorFactory.createIdentifierGenerator( identifierGeneratorStrategy, getType(), params );



and then in
Code:
DefaultIdentifierGeneratorFactory
I have other config, maybe here something is missing.. ?

Code:
strategy = "sequence"
type = {LongType@9670}
config = {Properties@9547}  size = 8
0 = {Hashtable$Entry@9675} "identifier_normalizer" ->
1 = {Hashtable$Entry@9676} "entity_name" -> "........"
2 = {Hashtable$Entry@9677} "target_table" -> "............"
3 = {Hashtable$Entry@9678} "jpa_entity_name" -> ".........."
4 = {Hashtable$Entry@9679} "identity_tables" -> ".........."
5 = {Hashtable$Entry@9680} "hibernate.id.optimizer.pooled.prefer_lo" -> "false"
6 = {Hashtable$Entry@9681} "sequence" -> "MY_SEQ"
7 = {Hashtable$Entry@9682} "target_column" -> "ID"
clazz = {Class@9671} "class org.hibernate.id.enhanced.SequenceStyleGenerator"
serviceRegistry = {StandardServiceRegistryImpl@8648}


Code:
public Class getIdentifierGeneratorClass(String strategy) (strategy=sequence)


Code:
generatorStrategyToClassNameMap = {ConcurrentHashMap@9705}  size = 14
0 = {ConcurrentHashMap$MapEntry@9708} "select" -> "class org.hibernate.id.SelectGenerator"
1 = {ConcurrentHashMap$MapEntry@9709} "increment" -> "class org.hibernate.id.IncrementGenerator"
2 = {ConcurrentHashMap$MapEntry@9710} "seqhilo" -> "class org.hibernate.id.SequenceHiLoGenerator"
3 = {ConcurrentHashMap$MapEntry@9711} "uuid" -> "class org.hibernate.id.UUIDHexGenerator"
4 = {ConcurrentHashMap$MapEntry@9712} "uuid.hex" -> "class org.hibernate.id.UUIDHexGenerator"
5 = {ConcurrentHashMap$MapEntry@9713} "foreign" -> "class org.hibernate.id.ForeignGenerator"
6 = {ConcurrentHashMap$MapEntry@9714} "uuid2" -> "class org.hibernate.id.UUIDGenerator"
7 = {ConcurrentHashMap$MapEntry@9715} "sequence" -> "class org.hibernate.id.enhanced.SequenceStyleGenerator"
8 = {ConcurrentHashMap$MapEntry@9716} "enhanced-table" -> "class org.hibernate.id.enhanced.TableGenerator"
9 = {ConcurrentHashMap$MapEntry@9717} "identity" -> "class org.hibernate.id.IdentityGenerator"
10 = {ConcurrentHashMap$MapEntry@9718} "enhanced-sequence" -> "class org.hibernate.id.enhanced.SequenceStyleGenerator"
11 = {ConcurrentHashMap$MapEntry@9719} "guid" -> "class org.hibernate.id.GUIDGenerator"
12 = {ConcurrentHashMap$MapEntry@9720} "sequence-identity" -> "class org.hibernate.id.SequenceIdentityGenerator"
13 = {ConcurrentHashMap$MapEntry@9721} "assigned" -> "class org.hibernate.id.Assigned"



Code:
if ( identifierGenerator instanceof Configurable ) {
            ( ( Configurable ) identifierGenerator ).configure( type, config, serviceRegistry );
         }


Last edited by herbatniczek on Tue Jun 21, 2016 10:32 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: HIbernate 5: ORA-02289: sequence does not exist
PostPosted: Tue Jun 21, 2016 10:23 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I think `DefaultIdentifierGeneratorFactory` does not take into consideration the old identifiers.

Does it work if you change the mapping like this:

Code:
<generator class="org.hibernate.id.SequenceGenerator">
    <param name="sequence">MY_SEQ</param>
</generator>


Top
 Profile  
 
 Post subject: Re: HIbernate 5: ORA-02289: sequence does not exist
PostPosted: Tue Jun 21, 2016 10:36 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
Thanks very much, it seems to have helped however this generator is marked deprecated :(

As for above I think here something breaks (maybe CONFIG_PREFER_SEQUENCE_PER_ENTITY, CONFIG_SEQUENCE_PER_ENTITY_SUFFIX ??):

And here something breaks..

Code:
SequenceStyleGenerator.determineSequenceName



Code:
protected QualifiedName determineSequenceName(Properties params, Dialect dialect, JdbcEnvironment jdbcEnv) {
      final String sequencePerEntitySuffix = ConfigurationHelper.getString( CONFIG_SEQUENCE_PER_ENTITY_SUFFIX, params, DEF_SEQUENCE_SUFFIX );
      // JPA_ENTITY_NAME value honors <class ... entity-name="..."> (HBM) and @Entity#name (JPA) overrides.
      final String defaultSequenceName = ConfigurationHelper.getBoolean( CONFIG_PREFER_SEQUENCE_PER_ENTITY, params, false )
            ? params.getProperty( JPA_ENTITY_NAME ) + sequencePerEntitySuffix
            : DEF_SEQUENCE_NAME;

      final String sequenceName = ConfigurationHelper.getString( SEQUENCE_PARAM, params, defaultSequenceName );
      if ( sequenceName.contains( "." ) ) {
         return QualifiedNameParser.INSTANCE.parse( sequenceName );
      }
      else {
         // todo : need to incorporate implicit catalog and schema names
         final Identifier catalog = jdbcEnv.getIdentifierHelper().toIdentifier(
               ConfigurationHelper.getString( CATALOG, params )
         );
         final Identifier schema =  jdbcEnv.getIdentifierHelper().toIdentifier(
               ConfigurationHelper.getString( SCHEMA, params )
         );
         return new QualifiedNameParser.NameParts(
               catalog,
               schema,
               jdbcEnv.getIdentifierHelper().toIdentifier( sequenceName )
         );
      }
   }
      


Code:
sequencePerEntitySuffix = "_SEQ"
defaultSequenceName = "hibernate_sequence"
sequenceName = "hibernate_sequence"


Top
 Profile  
 
 Post subject: Re: HIbernate 5: ORA-02289: sequence does not exist
PostPosted: Tue Jun 21, 2016 10:42 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
You can still use the `SequenceStyleGenerator`, but only if the incremental step is set to 1.

However, `SequenceStyleGenerator` uses different parameter names, so you'll have to change sequence to sequence_name.


Top
 Profile  
 
 Post subject: Re: HIbernate 5: ORA-02289: sequence does not exist
PostPosted: Tue Jun 21, 2016 10:48 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
I created HHH-10876 for this issue.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.