I am developing an application using oracle 11g, Java(struts2) and Hibernate.
I have table named mytemp with column mytemp_id which is of type NUMBER(22,0).
In my mytemp.hbm.xml file id is as given 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 sequence named "MYTEMP_TEMP_ID_SEQ" is created and working fine in Oracle.
Now when I try to insert record using hibernate, it gives me following error
org.hibernate.id.IdentifierGenerationException: this id generator generates long, integer, short or string
It seems that as my sequence returns Number, hibenate considering it as BigDecimal, while hibernate's sequece generator class considering values that are long, integer, short and string only.
Hibernate should not have problem with BigDecimal. But I think they have not implemented BigDecimal for sequence generator
Can any one help me solving the problem?
Thanks.
To be honest with you, I can't imagine why you would insist on having your ID as BigDecimal instead of long. Maximum long value is 9,223,372,036,854,775,807
which, although admittedly is about one thousandth of maximum NUMBER(22) value, should really be quite enough. If you were to generate one million identifiers every second, you would have to do that for 300,000 years in order to exhaust your sequence.
That said, in order to have your identifier generated as BigDecimal you will need to write your own generator. You can do that by extending Hibernate's built-in SequenceGenerator and overriding its generate()
method. Instead of calling through to IdentifierGeneratorFactory.get()
which only supports long / int / short / String you'd obtain your sequence value from result set as BigDecimal.
You will then need to declare your generator by specifying its full class name:
<generator class="com.mypackage.BigDecimalGenerator">
<param name="sequence">MYTEMP_TEMP_ID_SEQ</param>
</generator>