You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by INANDJO TAUREL <in...@hotmail.com> on 2001/08/28 12:11:52 UTC
how to get the primary key after object.save()
I have a class called Level in which I have a createLevel method ...
public static Level createLevel(Level parent, String name){
l.setName(name);
l.setParentid(parent.getPrimaryKey()); l.save(); return l;}
The problem I have is when I pass this newly created level and try to
create another level with this level as its parent.
After l.save() is called, I log the following l.getRowid() <--- shows null
l.getPrimaryKey() <--- shows null (rowid equivalent to primary key)
l.getPrimaryKeyAsInt() <--- shows -1
I also tried changing BaseLevelPeer.java so that in the function with
signature void doInsert(Level l, DbCon dc), doInsert(buildCriteria(l), dc);
obj.setNew(false);is replaced by
ObjectKey ok = doInsert(buildCriteria(l), dc); l.setPrimaryKey(ok);
obj.setNew(false);I even tried Criteria c = new Criteria();
c.remove(LevelPeer.ROWID); ObjectKey ok = doInsert(c, dc);
l.setPrimaryKey(ok); obj.setNew(false);
So how does one get the primary key of a newly created object ?
I am using TDK 2.1 final and MySQL database ...
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org