Hi I have two classes, and all I'm trying to do is use the primary key in one to populate the foreign key using a foreign generator class.
Code:
<class name="org.thorne.lettings.referencedata.api.AddressImpl" table="address">
<id name="id" column="id" unsaved-value="-1">
<generator class="identity"/>
</id>
<property name="line1" column="line1"/>
<property name="line2" column="line2"/>
<property name="line3" column="line3"/>
<property name="country" column="country"/>
<property name="locationCode" column="locationCode"/>
<many-to-one name="party" class="org.thorne.lettings.referencedata.api.PartyImpl" column="party_id_fk" cascade="save-update" />
<one-to-one name="coordinates" class="org.thorne.lettings.referencedata.api.CoordinatesImpl" foreign-key="address_id_fk" cascade="save-update" />
</class>
<class name="org.thorne.lettings.referencedata.api.CoordinatesImpl" table="address_os_coords" >
<id name="address" column="address_id_fk">
<generator class="foreign">
<param name="property">address</param>
</generator>
</id>
<one-to-one name="address" class="org.thorne.lettings.referencedata.api.AddressImpl" constrained="true" />
<property name="x" column="x"/>
<property name="y" column="y"/>
</class>
my tables look like
CREATE TABLE address (
id int AUTO_INCREMENT NOT NULL,
line1 varchar(100) NOT NULL,
line2 varchar(100) NULL,
line3 varchar(100) NULL,
locationCode varchar(10) NOT NULL,
country varchar(10) NOT NULL,
party_id_fk int NULL,
PRIMARY KEY (id),
INDEX party_ind(party_id_fk),
FOREIGN KEY (party_id_fk) REFERENCES party(id)
) TYPE=InnoDB;
CREATE TABLE address_os_coords (
x int NOT NULL,
y int NOT NULL,
address_id_fk int NOT NULL,
INDEX address_ind(address_id_fk),
FOREIGN KEY (address_id_fk) REFERENCES address(id)
) TYPE=InnoDB;
When I create an address and set some coordinates for I get this:
Hibernate: insert into address (line1, line2, line3, country, locationCode, party_id_fk) values (?, ?, ?, ?, ?, ?)
Hibernate: select last_insert_id()
Hibernate: update address_os_coords set x=?, y=? where address_id_fk=?
org.springframework.orm.hibernate.HibernateSystemException: Batch update row count wrong: 0; nested exception is net.sf.hibernate.HibernateException: Batch update row count wrong: 0
net.sf.hibernate.HibernateException: Batch update row count wrong: 0
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:65)
I could easily get this to work by putting coordinates into the Address table
but I wanted to keep it separate.
Anyone got any ideas?
thanks,
Neil