Hibernate 2.1
MySQL 4.1.3
I have a problem in a <many-to-one cascade="all" name="address"/> association in the definition of 'BuyerOrganisation'.
- If I try to save BuyerOrganisation and flush the session I get an exception 'Batch update row count wrong: 0'
- If I don't flush at the end hibernate doesn't say anything but the address is not stored in the database, however the foreign key for address in the buyerorg table is set to 0 (which is the default before hibernate assigns an ID to it)
- If I save the address first and then the buyer organisation things go right.
It seems that it either doesn't cascade or it cascades the wrong way around (first the organisation then the address) Any idea what I could be doing wrong? Any help is appreciated.
Thanks,
Vincent
--
I have the following hibernate definition:
Code:
<hibernate-mapping package="nl.xiam.infomas.sx.model">
<class name="BuyerOrganisation">
<id name="id" column="buyerOrgID">
<generator class="native"/>
</id>
<property name="name" length="32"/>
<many-to-one name="address" cascade="all"/>
...mode defs....
</class>
</hibernate-mapping>
And address:
Code:
<hibernate-mapping package="nl.xiam.infomas.bx.model">
<class name="Address">
<id name="id" column="addressID">
<generator class="native"/>
</id>
... all properties ...
</class>
</hibernate-mapping>
Code:
Session ses = _sessionFactory.openSession();
BuyerOrganisation bo = new BuyerOrganisation();
bo.setName("Some Org");
Address a = new Address();
a.setStreet("SomeStreet 32");
a.setPostal("12345");
a.setCity("Amersfoort");
a.setCountry("NL");
//ses.save(a); // uncomment and things go right
bo.setAddress(a);
ses.save(bo);
ses.flush(); // comment and it doesn't store the address, but doesn' t except either
ses.disconnect();
I'm using spring and hibernate, but that doesn't matter.
Code:
SEVERE: Could not synchronize database state with session
net.sf.hibernate.HibernateException: Batch update row count wrong: 0
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:65)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:126)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2421)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2372)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2240)
at nl.xiam.infomas.sx.command.PopulateDatabase.createBuyerAndOrganisation(PopulateDatabase.java:112)
at nl.xiam.infomas.sx.command.PopulateDatabase.main(PopulateDatabase.java:63)