0

I am getting error while creating auto generated key for a string primary key error: org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String HBM.XML below

<class name="CmRetroEvt" table="CM_RETRO_EVT" schema="CISADM" >
    
        <id name="ext_source_id" type="string" column="EXT_SOURCE_ID">
            <generator class="sequence">
            <param name="sequence_name">EXT_SOURCE_ID_SEQ_NBR</param>
            </generator>
        </id>

Got the following error any plz suggest what needs to be done to overcome this issue :-

org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String
  • I'd have to dig in the documentation a little but the problem seems to be that a string cannot just be incremented, i.e. the next value in the sequence cannot be generated for a string. Try a numeric type like int or long or look for a sequence generator that works with strings. – Thomas Sep 08 '22 at 12:22
  • @Thomas I have looked uuid generator works for strings but I am not sure how to put the configuration in xml – Nitesh Sharma Sep 08 '22 at 12:25
  • Did you try `class="uuid"` or `class="uuid2"`? It might depend on the version of Hibernate you're using. Btw, would it be an option to go for annotation based configuration instead? – Thomas Sep 08 '22 at 12:31
  • @Thomas I will try class="uuid" but annotation based is not possible now – Nitesh Sharma Sep 08 '22 at 12:38
  • @Thomas uuid is giving java.sql.SQLException: ORA-12899: value too large for column "CISADM"."CM_RETRO_EVT"."EXT_SOURCE_ID" (actual: 32, maximum: 30) I need to follow the sequence EXT_SOURCE_ID_SEQ_NBR – Nitesh Sharma Sep 08 '22 at 13:04
  • Well, then ou might have to find some other sequence generator that is able to work with strings. If none of the built-ins work you can always create your own as a last resort. – Thomas Sep 08 '22 at 14:34
  • See https://stackoverflow.com/questions/31158509/how-to-generate-custom-id-using-hibernate-while-it-must-be-primary-key-of-table – Christian Beikov Sep 09 '22 at 12:24

0 Answers0