Hibernate Oracle sequence generator problem

I am developing an application using oracle 11g, Java (struts2) and Hibernate.

I have a table called mytemp with a column mytemp_id that is of type NUMBER (22.0).

In my file mytemp.hbm.xml the file is listed below

<id name="mytempId" type="big_decimal">
        <column name="MYTEMP_ID" precision="22" scale="0" />
        <generator class="sequence">
            <param name="sequence">MYTEMP_TEMP_ID_SEQ</param>
        </generator>
    </id>

In my Oracle database, a database is created with the name "MYTEMP_TEMP_ID_SEQ", which works fine in Oracle.

Now when I try to insert a record using sleep mode, it gives me the following error

org.hibernate.id.IdentifierGenerationException: this id generator throws long, integer, short or string

It seems that as my sequence returns Number, hibenate treats it as BigDecimal, and the sleep generator class allocates values ​​that are long, integer, short, and string.

Hibernation should not have a problem with BigDecimal. But I think they did not implement BigDecimal for the sequence generator

Can someone help me solve the problem?

Thanks.

+3
source share
3 answers

, , , ID BigDecimal, . 9,223,372,036,854,775,807, , , , NUMBER (22), . , 300 000 , .

, BigDecimal, . , Hibernate SequenceGenerator generate(). IdentifierGeneratorFactory.get(), long/int/short/String, BigDecimal.

, :

<generator class="com.mypackage.BigDecimalGenerator">
  <param name="sequence">MYTEMP_TEMP_ID_SEQ</param>
</generator>
+13

? , Hibernate .

[EDIT] , . ( Hibernate) long, integer, short string, BigDecimal.

ID "", Oracle . , Hibernate .

+2

. , , . , , - ( ).

In addition, the generator is database specific, such as the oracle, so the definition of dialact also matters.

+2
source

Source: https://habr.com/ru/post/1715159/


All Articles