ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Brian Parkinson" <pa...@avaning.com>
Subject MySQL related question - constraint violation
Date Thu, 06 Dec 2007 13:46:23 GMT
Hello -

Wondering if someone out there has some MySQL experience - running into
a weird issue, and I'm stumped. This is perhaps not exactly an iBATIS
issue, but I received no response over at the MySQL forums, so it's
worth a shot:

I have a very simple data model working in iBATIS (getting familiar with
this, and enjoying how it's put together). It works on Windows and Mac
OS X, with MySQL version 5.0.45.

For our deployment, we're using Debian 5.0.32.

When I run my unit tests on the Debian box, I get foreign key constraint
violations which I do not get on the Windoze or Mac box. To wit:

    [junit] ------------- Standard Output ---------------
    [junit] --- The error occurred in
com/ecobee/foundation/ibatis/SqlMapThermostat.xml.  
    [junit] --- The error occurred while applying a parameter map.  
    [junit] --- Check the Thermostat.LocationParameterMap.  
    [junit] --- Check the statement (update failed).  
    [junit] --- Cause:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:
Cannot add or update a child row: a foreign key constraint fails
(`ecobee_test/Location`, CONSTRAINT `FK07` FOREIGN KEY (`ThermostatID`)
REFERENCES `thermostat` (`ThermostatID`) ON DELETE NO ACTION ON UPDATE
NO ACTION); nested exception is
com.ibatis.common.jdbc.exception.NestedSQLException:   
    [junit] --- The error occurred in
com/ecobee/foundation/ibatis/SqlMapThermostat.xml.  
    [junit] --- The error occurred while applying a parameter map.  
    [junit] --- Check the Thermostat.LocationParameterMap.  
    [junit] --- Check the statement (update failed).  
...

I've double checked the code, and I know it works as the unit tests on
Windoze and Mac are checking that everything works. The insert code
where the problem is:

	getSqlMapClient().startTransaction();
	getSqlMapClient().startBatch();
			
	int thermostatId = (Integer)
getSqlMapClientTemplate().insert("Thermostat.insert", thermostat);
			
	Location location = thermostat.getLocation();
	location.setThermostatId(thermostatId);
	getSqlMapClientTemplate().insert("Location.insert", location);

So, the location is certainly getting set with the proper thermostat
identifier, but the constraint is violated.

I've tried moving the Thermostat.insert out of the transaction/batch,
and a couple other things, but nothing works.

I guess the next step is to upgrade the Debian box, but it's a pretty
huge undertaking (a number of databases being used) and this seems that
there's something else going on.

Any ideas?

Appreciated, and thanks.

parki....



Mime
View raw message