From what I remember, if a table has native pk generation, then the
Criteria object which gets created on a save does not have any of the
primary key columns in it. I don't think you can have a composite pk
where only part of the pk is autoincremented.
Also, thinking about it, it doesn't make much sense to do so - the
autoincremented field is enough to be the primary key all by itself, so
why would you add another column to the pk - just make it a required
column, possibly create an index on it?
The method to create the Criteria has logic something like:
if (!isNew()) {
criteria.add(myPrimaryKeyColumn1);
criteria.add(myPrimaryKeyColumn2);
}
criteria.add(myOtherColumn3);
i.e. the pk columns don't get included for new objects when criteria are
generated. You could probably either:
a) Use Peer.doInsert(Criteria) to create your objects, and make the
Criteria what you want.
b) Override the method which creates the Criteria to:
setNew(false); super.getCriteria(); setNew(true);
c) Do something like: forum.save(); forum.setBoardId(4);
forum.save(); so that you do an update after the insert.
or d) Redesign the table so the primary keys don't have extraneous
columns.
Hope this helps
Gareth
On Thursday, August 29, 2002, at 08:26 pm, Michael Harris wrote:
> I have a table defined as such:
>
> <table name="bs_forum" javaName="ForumDao"
> idMethod="native">
> <column name="boardid" javaName="BoardId"
> required="true" autoIncrement="false"
> primaryKey="true" type="INTEGER"/>
> <column name="forumid" javaName="ForumId"
> required="true" autoIncrement="true" primaryKey="true"
> type="INTEGER"/>
> <column name="subject" javaName="Subject"
> required="false" type="VARCHAR" size="100"/> ...
> ---------------------------------------------------
> and I use the following code to populate it
>
> ForumDao forum = new ForumDao();
> forum.setNew(true);
> forum.setBoardId(4);
> forum.setSubject("fadfddfafd");
> forum.save();
>
> note that I purposely do not set forumId as I want it
> to autoincrement.
>
> Every time I insert a row the autoincrement on forumId
> works properly but boardId is always set to 0. So my
> real questions are:
>
> Am I doing something wrong?
> Does torque support composite keys?
>
> Thanks in advance for any help.
> MAH
>
>
> __________________________________________________
> Do You Yahoo!?
> Yahoo! Finance - Get real-time stock quotes
> http://finance.yahoo.com
>
> --
> To unsubscribe, e-mail: <mailto:turbine-torque-user-
> [EMAIL PROTECTED]>
> For additional commands, e-mail: <mailto:turbine-torque-user-
> [EMAIL PROTECTED]>
>
>
---
Development Team Leader, eGS, 5-7 Singer Street, London EC2A 4BQ. +44
(0)20 7336 1440
CONFIDENTIALITY: This is email is confidential and intended solely for
the use of the individual to whom it is addressed.� Any views or
opinions presented are solely those of the author and do not necessarily
represent those of eGovernment Solutions (UK) Ltd.� If you are not the
intended recipient, be advised that you have received this email in
error and that any use, dissemination, forwarding, or copying of this
email is strictly prohibited.� If you have received this email in error
please contact the sender.
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>