I'm having an issue when trying to save a collection in an <idbag> under Hibernate with DB2. The error that results is a class cast exception, and it appears to result from the POST_INSERT_INDICATOR being used as the identifier instead of the actual long identifier. This occurs in LongType (ln 42) when trying to set the long value, and the value is actually the "POST_INSERT_INDICATOR" string.
I've read that you cannot use <generator class="native"/> for idbags:
http://www.hibernate.org/hib_docs/reference/en/html/collections.html#collections-idbag
I figured identity would work since I'm using DB2.
Hibernate version:
3.1.2
Name and version of the database you are using:
DB2 Version 9
Mapping documents:
Here's the idbag in Claim.hbm.xml:
Code:
<idbag name="standardTextSpecifications"
table="CLAIM_STD_TEXT_REL"
lazy="true" cascade="save-update">
<collection-id column="CLM_STD_TXT_ID" type="long">
<generator class="identity"/>
</collection-id>
<key column="CLM_ID"/>
<many-to-many column="STD_TXT_SPEC_ID"
class="StandardTextSpecification" fetch="join"/>
</idbag>
Full stack trace of any exception that occurs:Here's the stack trace of the ClassCastException. A Claim object is trying to be saved.:
java.lang.ClassCastException
at org.hibernate.type.LongType.set(LongType.java:42)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
at org.hibernate.persister.collection.AbstractCollectionPersister.writeIdentifier(AbstractCollectionPersister.java:749)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1031)
at org.hibernate.action.CollectionRecreateAction.execute(CollectionRecreateAction.java:26)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:143)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
The generated SQL:Code:
Hibernate: insert into CLAIM_STD_TEXT_REL (CLM_ID, CLM_STD_TXT_ID, STD_TXT_SPEC_ID) values (?, ?, ?)
Debug level Hibernate log excerpt:Code:
org.hibernate.type.LongType - INFO [main] - could not bind value 'POST_INSERT_INDICATOR' to parameter: 2; null
Here's the table definition of the join table, although it's not very suprising:
CREATE TABLE CLAIM_STD_TEXT_REL
(
CLM_STD_TXT_ID INTEGER NOT NULL
GENERATED ALWAYS
AS IDENTITY (
START WITH 1,
INCREMENT BY 1,
NO CACHE,
NO CYCLE
),
CLM_ID INTEGER NOT NULL ,
STD_TXT_SPEC_ID INTEGER NOT NULL
)
;
If anyone can offer any help I'd greatly appreciate it. For now I'm stuck mapping a persistent object for many of these similar join tables, and it really uglifies my data model. IdBag is created just for these situations and I'd like to use it.
Thanks,
Frank