Hibernate could not fetch the SequenceInformation from the database

前端 未结 4 1507
抹茶落季
抹茶落季 2020-11-30 09:58

I have recently updated hibernate in my application to 5.4.4.Final. And now, I have faced with the following exception during deployment.

ERROR [org.hibernat         


        
4条回答
  •  再見小時候
    2020-11-30 10:40

    In the end, I came up to the following solution:

    1. Create a sequence information extractor that extends SequenceInformationExtractorOracleDatabaseImpl:
    public class AppSequenceInformationExtractor extends SequenceInformationExtractorOracleDatabaseImpl 
    {
       /**
        * Singleton access
        */
       public static final AppSequenceInformationExtractor INSTANCE = new AppSequenceInformationExtractor();
       
       @Override
       protected Long resultSetMinValue(ResultSet resultSet) throws SQLException {
          return resultSet.getBigDecimal("min_value").longValue();
       }
    }
    
    1. Create a hibernate dialect that extends Oracle12cDialect:
    public class AppOracleDialect extends Oracle12cDialect
    {
       @Override
       public SequenceInformationExtractor getSequenceInformationExtractor() {
          return AppSequenceInformationExtractor.INSTANCE;
       }
       
       @Override
       public String getQuerySequencesString() {
          return "select * from user_sequences";
       }
    }
    
    1. And then use this dialect in the persistence.xml:
    
    

    As for the method getQuerySequencesString() overriding and usage USER_SEQUENCES instead of ALL_SEQUENCES it's debatable (See HHH-13322 and HHH-14022). But, in my case, the USER_SEQUENCES usage is preferable.

提交回复
热议问题