Ok, I am getting some exceptions with a many to many relationship. Hibernate 2.1.1 with MySQL on Windows running on WebSphere.
Here is the exception:
Code:
java.sql.BatchUpdateException: General error, message from server: "Column 'elementReferenceID' cannot be null"
Here is the SQL that hibernate executes:
Code:
insert into Relationship (lastModified, elementReferenceID, name, parentRelationship, type, deleted, instanceClass, relationshipID) values (?, ?, ?, ?, ?, ?, 'ManyToManyRelationship', ?)
insert into ElementReference (elementClass, elementName, elementDescription, element, elementID, referenceID) values (?, ?, ?, ?, ?, ?)
update Relationship set lastModified=?, elementReferenceID=?, name=?, parentRelationship=?, type=?, deleted=? where relationshipID=? and lastModified=?
insert into manytomany_elements (relationshipID, elementReferenceID) values (?, ?)
SQL Error: 1048, SQLState: S1000
General error, message from server: "Column 'elementReferenceID' cannot be null"
Here are my mappings:
<hibernate-mapping>
<class
name="com.forisent.framework.productManager.productOrganizer.store.entity.OneToManyRelationship"
table="Relationship"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="OneToManyRelationship"
>
<id
name="ID"
column="relationshipID"
type="java.lang.String"
length="32"
unsaved-value="none"
>
<generator class="uuid.hex">
</generator>
</id>
<discriminator
column="instanceClass"
type="string"
/>
<timestamp
name="lastModified"
column="lastModified"
/>
<many-to-one
name="element"
class="com.forisent.framework.productManager.productOrganizer.store.ElementReference"
cascade="all"
outer-join="auto"
update="true"
insert="true"
column="elementReferenceID"
not-null="false"
/>
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>
<many-to-one
name="parentRelationship"
class="com.forisent.framework.productManager.productOrganizer.store.Relationship"
cascade="all"
outer-join="auto"
update="true"
insert="true"
column="parentRelationship"
/>
<set
name="subRelationships"
lazy="false"
inverse="true"
cascade="all"
sort="unsorted"
>
<key
column="parentRelationship"
/>
<one-to-many
class="com.forisent.framework.productManager.productOrganizer.store.entity.OneToManyRelationship"
/>
</set>
<property
name="type"
type="java.lang.String"
update="true"
insert="true"
column="type"
/>
<property
name="deleted"
type="java.util.Date"
update="true"
insert="true"
column="deleted"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-OneToManyRelationship.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="com.forisent.framework.productManager.productOrganizer.store.entity.ManyToManyRelationship"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="ManyToManyRelationship"
>
<set
name="elements"
table="manytomany_elements"
lazy="false"
inverse="false"
cascade="all"
sort="unsorted"
>
<key
column="relationshipID"
/>
<many-to-many
class="com.forisent.framework.productManager.productOrganizer.store.ElementReference"
column="elementReferenceID" outer-join="auto"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ManyToManyRelationship.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
</class>
The column in question is bolded.
finally, here is my code being called:
Code:
try{
session = _SessionFactory.openSession();
tx = session.beginTransaction();
try{
session.saveOrUpdate(obj);
//session.flush();
}catch(HibernateException e){
if(tx != null) tx.rollback();
log.error("Rolling Back Persist Operation");
}
if(tx != null) tx.commit();
}catch(HibernateException e){
throw new PersistenceException(e.getMessage(), e);
}finally{
try{
if(session != null) session.close();
}catch(HibernateException e){
throw new PersistenceException(e.getMessage(), e);
}
}