I am having problems with cascading of save to array types, using the attacked code(see below): I am using Hypersonic, Hibernate is creating the following error:
Caused by: net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row not found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:25)
at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:538)
at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2382)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2339)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2204)
Can somebody point me in the right direction?
Thanks
[code]package hibtest;
public class TestTwo {
private Long id;
public TestTwo(Long id)
{
this.id = id;
}
/**
*
*/
public TestTwo() {
super();
}
/**
* @return
*/
public Long getId() {
return id;
}
/**
* @param long1
*/
public void setId(Long long1) {
id = long1;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if(obj == this)
{
return true;
}
else
{
if(obj instanceof TestTwo)
{
return this.id.equals(((TestTwo)obj).id);
}
}
return false;
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return this.id.hashCode();
}
}
[/code]
[code]
package hibtest;
public class TestRel {
private Long id;
private TestTwo[] related;
public TestRel(Long id,TestTwo[] related)
{
this.id = id;
this.related = related;
}
/**
*
*/
public TestRel() {
super();
}
/**
* @return
*/
public Long getId() {
return id;
}
/**
* @return
*/
public TestTwo[] getRelated() {
return related;
}
/**
* @param long1
*/
public void setId(Long long1) {
id = long1;
}
/**
* @param twos
*/
public void setRelated(TestTwo[] twos) {
related = twos;
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if(obj == this)
{
return true;
}
else
{
if(obj instanceof TestRel)
{
return this.id.equals(((TestRel)obj).id);
}
}
return false;
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return this.id.hashCode();
}
}
[/code][code]
public void testSimple() throws Exception
{
TestRel tr = new TestRel(new Long(-1), new TestTwo[]{new TestTwo(new Long(-1))});
Session s = factory.openSession();
Transaction tx = null;
ClassMetadata cme = factory.getClassMetadata(o.getClass());
Serializable ser = cme.getIdentifier(o);
try {
tx = s.beginTransaction();
Object obj = s.get(o.getClass(), ser);
if (obj == null) {
if (log.isDebugEnabled()) {
log.debug("Adding object to persistent cache " + o);
}
s.save(o);
}
s.flush();
tx.commit();
} catch (Exception e) {
if (tx != null)
tx.rollback();
throw e;
} finally {
s.close();
}
}
[/code]
[code]<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping default-cascade="save-update" auto-import="false">
<class name="hibtest.TestRel" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" batch-size="1" select-before-update="false" >
<id name="id">
<generator class="assigned"/>
</id>
<array name="related" lazy="false" inverse="false" cascade="all" outer-join="true">
<key column="related_id"/>
<one-to-many class="hibtest.TestTwo"/>
<index column="index" type="java.lang.String"/>
</array>
</class>
<class name="hibtest.TestTwo" mutable="true" polymorphism="implicit" dynamic-update="false" dynamic-insert="false" batch-size="1" select-before-update="false" >
<id name="id">
<generator class="assigned"/>
</id>
</class>
</hibernate-mapping>[/code]
|