-->
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.  [ 1 post ] 
Author Message
 Post subject: ID generation exception for id of type BigDecimal
PostPosted: Wed Dec 05, 2007 6:10 pm 
Newbie

Joined: Wed Dec 05, 2007 5:56 pm
Posts: 1
I am using hibernate 3.2.5.

I have a pojo with id defined as java.math.BigDecimal and associated to an oracle sequence. The following is the sample of mapping file

Code:
<hibernate-mapping>
    <class name="pojo.A" table="TABLE_A">
        <id name="id" type="big_decimal">
            <column name="ID" precision="22" scale="0" />
            <generator class="sequence">
                <param name="sequence">seq_a_id</param>
            </generator>
        </id>
    </class>
</hibernate-mapping>



When I persist the object I get the following exception,

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

I looked at the source code, it seems like the sequence is generated for int, short, long or String. If I add 3 lines of code (marked below) it works.

Code:
      // unhappy about this being public ... is there a better way?
        public static Serializable get(ResultSet rs, Type type)
        throws SQLException, IdentifierGenerationException {

                Class clazz = type.getReturnedClass();
                if ( clazz==Long.class ) {
                        return new Long( rs.getLong(1) );
                }
                else if ( clazz==Integer.class ) {
                        return new Integer( rs.getInt(1) );
                }
                else if ( clazz==Short.class ) {
                        return new Short( rs.getShort(1) );
                }
                else if ( clazz==String.class ) {
                        return rs.getString(1);
                }

               //added the following 3 lines
                else if ( clazz==java.math.BigDecimal.class ) {
                        return rs.getBigDecimal(1);
                }
                else {
                        throw new IdentifierGenerationException("this id generator generates long, integer, short or string");
                }

        }


Is there a JIRA # already opened for this? If yes then is there a plan to include the fix in next release ?

In the meantime can I change the code and use the modified jar file without licensing issue? Is this the right fix even?

_________________
Common Sense is not very common.
-Voltaire


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

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.