-->
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.  [ 3 posts ] 
Author Message
 Post subject: ClassCast exception using an IdBag and composite-element
PostPosted: Wed Aug 03, 2005 5:57 am 
Newbie

Joined: Tue May 25, 2004 11:42 am
Posts: 10
Location: Oxford, England
Hibernate version:
3.0.5
Mapping documents:
Code:
   <class name="core.data.Company" table="company" select-before-update="true" >
      <id name="id" type="int" column="companyID" unsaved-value="0">
         <generator class="native"/>
      </id>
... some standard properties ....

        <idbag name="ouOutSvr" table="ououtsvr" cascade="all" lazy="false">
            <collection-id column="OUOutSvrId" type="int">
                <generator class="native"/>
            </collection-id>
            <key column="companyID"/>
            <composite-element class="insl.core.data.OUOutSvr">
                <property name="svrIP" column="svrIP" type="string"/>
                <property name="description" column="description" type="string"/>
                <property name="activated" column="activated" type="int"/>
            </composite-element>
        </idbag>
   </class>


Full stack trace of any exception that occurs:
Code:
java.lang.ClassCastException: java.lang.String
   at org.hibernate.type.IntegerType.set(IntegerType.java:39)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:62)
   at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:44)
   at org.hibernate.persister.collection.AbstractCollectionPersister.writeIdentifier(AbstractCollectionPersister.java:699)
   at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:908)
   at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:23)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:730)


Name and version of the database you are using:
MySQL 4.1

The generated SQL (show_sql=true):
Hibernate: insert into ououtsvr (companyID, OUOutSvrId, svrIP, description, activated) values (?, ?, ?, ?, ?)
NullableType.nullSafeSet - binding '28' to parameter: 1
NullableType.nullSafeSet - binding '' to parameter: 2


Further Investigations
The error occurs when I attempt to add a new object to the OUOutSvr list.
I've been tracing the problem through the system and the problem occurs in the IntegerType class's set method because it attempts to cast the value to an Integer.
Code:
   public void set(PreparedStatement st, Object value, int index)
   throws SQLException {
      st.setInt( index, ( (Integer) value ).intValue() );
   }

The value of the value parameter as this point is an empty string. The empty string has been provided by the AbstractPostInsertGenerator class in the method generate which is simply returning the constant POST_INSERT_INDICATOR which == '' (empty string).
Code:
   public Serializable generate(SessionImplementor s, Object obj) {
      return IdentifierGeneratorFactory.POST_INSERT_INDICATOR;
   }


I have created a simple test to reproduce the problem. It simply loads a Company object and adds a new OUOutSvr object to the List and then calls flush().
Code:
        OUOutSvr svr1 = new OUOutSvr(0, "1.1.1.1", "desc", 1);
        co.getOuOutSvr().add(svr1);
        HibernateUtil.currentSession().flush();



Is this a bug? or is there something wrong with my configuration?


Top
 Profile  
 
 Post subject: Wrong generator?
PostPosted: Wed Aug 03, 2005 2:06 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Quote:
In the current implementation, the native identifier generation strategy is not supported for <idbag> collection identifiers.

http://www.hibernate.org/hib_docs/v3/re ... ions-idbag


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 04, 2005 3:05 am 
Newbie

Joined: Tue May 25, 2004 11:42 am
Posts: 10
Location: Oxford, England
Yes - I had read that. I have tried "identity" and "native" and both cause the same issue.


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

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.