Howdy. I have three tables: section, option and position. The relationship between each is 1:n (so there can be n options per 1 section and n positions per 1 option). There are no foreign keys which reference the option table.
I'm trying to write code to delete a section and all the options and
positions associated with it. In trying to select all the associated
options, I do the following:
Criteria crit = new Criteria();
crit.add(PositionPeer.SECTION_ID, getSectionId());
crit.addJoin(SectionPeer.SECTION_ID, PositionPeer.SECTION_ID);
crit.addJoin(PositionPeer.POSITION_ID, OptionPeer.POSITION_ID);
OptionPeer.doDelete(crit);
When this segment gets run, however, the following occurs:
3361 [main] DEBUG org.apache.torque.util.BasePeer - BasePeer.doDelete:
whereClause=SECTION_ID=2
org.apache.torque.TorqueException: ERROR: <unnamed> referential integrity violation -
key in position still referenced from option
It appears that a deletion from position (rather than option) is being
attempted. I've surrounded the code in question with logging statements,
so I'm quite certain of its position.
Calling OptionPeer.doSelect(crit) for this same criteria results in the
correct data being returned. Indeed, the following (less efficient) code
snippet works:
crit = new Criteria();
crit.add(PositionPeer.SECTION_ID, getSectionId());
crit.addJoin(SectionPeer.SECTION_ID, PositionPeer.SECTION_ID);
crit.addJoin(PositionPeer.POSITION_ID, OptionPeer.POSITION_ID);
Vector v = OptionPeer.doSelect(crit);
for(int i=0; i<v.size(); i++) {
((Option)(v.elementAt(i))).remove();
}
where Option.remove() is simply a call to OptionPeer.doDelete(this)
Anyone know what's going on here?
Thanks!
msg06706/pgp00000.pgp
Description: PGP signature
