I am having the same problem, although with a different type of table that
might shed more light on the subject.
My table has 1 primary key which is a string; my "domain" column. (The XML
is at the bottom of this message.) When I try this :
DomainMapperEntry dme = new DomainMapperEntry();
dme.setDomain("someDomain");
dme.save();
I get the error "Invalid argument value: Duplicate entry '' for key 1",
meaning that the "domain" column is being set to an empty string, and not to
"someDomain". I also tracked this back to the buildCriteria() method in my
Peer, and saw that domain will *not* be put in the criteria because primary
keys are not included with inserts, only updates. That makes sense for
prikeys that are autogenerated by the database, but my key is not
autogenerated. I commented out the line :
if ( !obj.isNew() )
in the buildCriteria, so that my primary key will always be added.I have not
(after *very little* testing) had any trouble; my objects are now being
saved. I'm assuming that the if statement does belong there for some reason
though, and I'm nervous to leave it out in production.
tia for any help,
Roy
<table name = "Domain_Mapper"
javaName = "DomainMapperEntry">
<column
name="domain"
required="true"
primaryKey="true"
type="VARCHAR"
size="30"/>
<column
name="company_id"
type="INTEGER"
/>
<column
name="autoMapPeople"
required="true"
type="BIT"
default="1"
/>
<foreign-key foreignTable="Companies">
<reference
local="company_id"
foreign="company_id"/>
</foreign-key>
</table>
---------------------------
An interesting update.
The problem lies in the fact that the table only consists of two foreign
keys.
The code in buildCriteria() will NEVER add the values for an insert because
both table entries are listed as primaryKeys, which in the generated code
only get added to criteria on an update.
However, one cannot simply not list the columns as primary keys, as this
generates compile errors.
What's the correct solution to this problem that does not involve always
editing the BaseXXXPeer class?
-Andrew
-----Original Message-----
From: Andrew [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 31, 2002 12:22 PM
To: Torque Users List (E-mail)
Subject: Bizarre error inserting a new row (Torque claims that there's
no data to insert)
This is happening, currently, to one of my tables.
I am doing:
ConversationMessageDO om = new ConversationMessageDO();
om.setMessageID("1");
om.setConversationID("2");
om.save();
Those two fields are the only rows on this column. This is an intersect
table, and both rows point to other tables, if that helps.
When I try to do this I get the following exception thrown at me:
org.apache.torque.TorqueException: Database insert attempted without
anything sp
ecified to insert
at org.apache.torque.util.BasePeer.doInsert(BasePeer.java:839)
at
com.uniti.db.om.BaseConversationMessageDOPeer.doInsert(BaseConversati
onMessageDOPeer.java:152)
at
com.uniti.db.om.BaseConversationMessageDOPeer.doInsert(BaseConversati
onMessageDOPeer.java:417)
at
com.uniti.db.om.BaseConversationMessageDO.save(BaseConversationMessag
eDO.java:376)
at
com.uniti.db.om.BaseConversationMessageDO.save(BaseConversationMessag
eDO.java:341)
at
com.uniti.db.om.BaseConversationMessageDO.save(BaseConversationMessag
eDO.java:324)
I spent a good deal of time perusing the source code to find out whats up.
The last line called in BaseConversationMessageDOPeer calls doInsert on the
BasePeer class, as you can see from the trace. The parameters it passes are
a Criteria and DBConnection. The interesting bit is that the Criteria seems
to be completely empty. Why? Because in buildCriteria() it only ads
information to the criteria object if the object is not new. Well the object
is of course new since we are doing an insert.
Anyone know whats up with this? This doesn't seem to happen with all
classes. I am most perplexed.
Thanks.
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>