You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by joe black <ch...@hotmail.com> on 2001/08/28 10:53:18 UTC

Generate ID when OM is created, can I?

Suppose ClassRoom is an OM

ClassRoom classRoom=new ClassRoom();
classRoom.set...
...
classRoom.save();   
...

A primary key will be generated and retreived in the save() method, how? After inserting, select the latest record which have the equivalent attributes( could it be a little dangerous? ), I guess. Anyway, maybe the select operation cost more than inserting and the user didn't want the generated ID at all.

Can IDBroker make a new ID for an OM as soon as this OM is created?  If could, we can do like this...

ClassRoom classRoom=new ClassRoom(); //It has an ID now
Student s1=new Student();   
s1.setClassRoomId(classRoom.getId().getBigDecimal().intValue()); //or Student s1=classRoom.createNewStudent();
s1.set....
...

Student s2=new Student();
s2.setClassRoomId(classRoom.getId().getBigDecimal().intValue());
s2.set...
...

classRoom.set....
...

s1.save(conn);
s2.save(conn);
classRoom.save(conn);
conn.commit()

Just a thought  ;-)Get more from the Web.  FREE MSN Explorer download : http://explorer.msn.com