Your rawRowsForSql call through an exception because you are completely bypassing the primary key generation process, so it you want to insert rows using this call, you need to generate the primary keys yourself.
I used to know how to do this using only WebObjects classes, but I cannot remember any longer. But this works with Wonder classes. There may be a better way to get to the EOAdaptorChannel.Delegate, but I always seem to re-find the chain one has to follow. You can get the EODatabaseContext at any point that you have an eo and use that to get the EOAdaptorChannel. Once you have them, you do not need to find them again. In the code below, the setDelegate methods end up getting called more often than they need to be, but since I am using singletons for the delegate instances, this is harmless. I ran this and verified, after turning on the EOAdaptorDebugEnabled flag, I get:
Sep 04 15:07:54 TreeFul[51162] DEBUG NSLog - evaluateExpression: <com.webobjects.jdbcadaptor.MySQLPlugIn$MySQLExpression: "INSERT DELAYED INTO c_tree_closure(down, up, distance) VALUES (?, ?, ?)" withBindings: 1:39(down), 2:39(up), 3:0(distance)>
eosqlexpression statement: INSERT DELAYED INTO c_tree_closure(down, up, distance) VALUES (?, ?, ?)
Sep 04 15:07:54 TreeFul[51162] DEBUG NSLog - evaluateExpression: <com.webobjects.jdbcadaptor.MySQLPlugIn$MySQLExpression: "INSERT DELAYED INTO c_tree_closure(down, up, distance) VALUES (?, ?, ?)" withBindings: 1:39(down), 2:1(up), 3:1(distance)>
So, it does work. Anyway, good luck.
cheers - ray
This is pulled from a Main.java:
public class Main extends ERXComponent {
public Main(WOContext context) {
super(context);
}
<snip>
public WOActionResults editStuff() {
<snip>
EOEnterpriseObject eo = EOUtilities.createAndInsertInstance(ec, "MyEntity");
EODatabaseContext dbc = ERXEOAccessUtilities.databaseContextForObject(pObj);
dbc.setDelegate(dbcd);
<snip>
}
static DBCDelegate dbcd = new DBCDelegate();
static ACDelegate acd = new ACDelegate();
public static class DBCDelegate {
public NSArray databaseContextWillPerformAdaptorOperations(
EODatabaseContext eodatabasecontext,
NSArray nsarray,
EOAdaptorChannel eoadaptorchannel) {
eoadaptorchannel.setDelegate(acd);
return nsarray;
}
}
public static class ACDelegate {
public boolean adaptorChannelShouldEvaluateExpression(
EOAdaptorChannel eoadaptorchannel,
EOSQLExpression eosqlexpression) {
if (eosqlexpression.statement().startsWith("INSERT")) {
String sql = eosqlexpression.statement().replaceAll("INSERT", "INSERT DELAYED");
eosqlexpression.setStatement(sql);
}
return true;
}
}
}