Hi, All,
Can anyone give me some guidance on this really simple question. How do you
insert multiple new records in to a single table in one transaction?
Creating the first object instance to represent the first record is fine.
I'm getting stuck when I want to create the second object instance because
Castor insists that I'm trying to duplicate the first instance. I need to
put some code inside an iterative control structure because the number of
new records (object instances) is indefinite.

This is as far as I have got:-

Enumeration e;        // contains the list of strings.
                          // We want to store each string in a new record.
intEmailAID  int;     //variable for managing the value of the identity
field.
/*  ..
set up database connection, etc
.. */

db.begin();           // begin a transaction

EmailAJDO em = new EmailAJDO(); //set up a new instance of an 'EMailAJDO'
object.
                                          //This maps to a record in the 'EmailA' 
table.

//loop through the e enumeration
while (e.hasMoreElements()){
        em.setEmailAID(intEmailAID);           // EmailAID is the identity field.
        em.setAddress((String)e.nextElement());
        db.create(em);                         //Fails here on second time around
the loop.
                                                        /*Exception message:
                                                        "Duplicate identity found for 
object of type model.EmailAJDO
                                                        with identity 5: an object 
with the same identity already exists
                                                         in persistent storage" */

        intEmailAID = intEmailAID+1;        //increment the identity field
 }
// Commit the transaction
db.commit();

There must be a simple way of doing this 'cos it's one of the most basic
database operations.
Any offers?

Many thanks
Steve

======================
Steve Farndon
Alpha Telesystems Ltd.
Tel: 0161-902-9212
Fax: 0161-902-9011

----------------------------------------------------------- 
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to