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 InvestigationsThe 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?