You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Jeffery Painter <pa...@kiasoft.com> on 2003/04/16 16:35:59 UTC

old question about retrieving PrimaryKey from new object

I know I've read the posts many many times about returning the primary key 
of a newly formed base object, and I thought I had figured it all out.

However, I'm running into a wall with an action trying to do a complex 
insert of multiple objects from one form.

I have the following code but it is returning null for the primary keys

database is set to use idbroker and keys are autoincrement, mysql database

my action doInsert method

	Date now = new Date();
        Participant entry = new Participant();
        Address branchAddress = new Address();
        Address mailingAddress = new Address();

        data.getParameters().setProperties(entry);
        entry.setDateCreated(now);
        entry.setDateModified(now);

        branchAddress.setNew(true);
        branchAddress.save();

        mailingAddress.setNew(true);
        mailingAddress.save();

        entry.setBranchAddressId( branchAddress.getPrimaryKey() );
        entry.setMailingAddressId( mailingAddress.getPrimaryKey() );

	entry.setNew(true);
        entry.save();

my participant object has the following base methods generated from torque

 public void setBranchAddressId(NumberKey v )
 public void setBranchAddressId(String v )
 public void setAddressRelatedByBranchAddressId(Address v)

I've tried using all three methods, however, they all end up being null

Am I missing a step here? shouldn't the primary key be available after the 
save method or is there something else I need to do.


Thanks,

Jeff Painter
painter@kiasoft.com


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: old question about retrieving PrimaryKey from new object

Posted by Michael Mainguy <ma...@mich.com>.
I'm assuming you're autoincrement field is an integer, have you tried 
branchAddress.getID() {or whatever the field name is?)
That works for me...
I also noticed there is a setBranchAddress(BranchAddress a) on my Base
Objects, perhaps that would work too (I haven't tried it though).


On Wed, 2003-04-16 at 10:35, Jeffery Painter wrote: 
> 
> I know I've read the posts many many times about returning the primary key 
> of a newly formed base object, and I thought I had figured it all out.
> 
> However, I'm running into a wall with an action trying to do a complex 
> insert of multiple objects from one form.
> 
> I have the following code but it is returning null for the primary keys
> 
> database is set to use idbroker and keys are autoincrement, mysql database
> 
> my action doInsert method
> 
> 	Date now = new Date();
>         Participant entry = new Participant();
>         Address branchAddress = new Address();
>         Address mailingAddress = new Address();
> 
>         data.getParameters().setProperties(entry);
>         entry.setDateCreated(now);
>         entry.setDateModified(now);
> 
>         branchAddress.setNew(true);
>         branchAddress.save();
> 
>         mailingAddress.setNew(true);
>         mailingAddress.save();
> 
>         entry.setBranchAddressId( branchAddress.getPrimaryKey() );
>         entry.setMailingAddressId( mailingAddress.getPrimaryKey() );
> 
> 	entry.setNew(true);
>         entry.save();
> 
> my participant object has the following base methods generated from torque
> 
>  public void setBranchAddressId(NumberKey v )
>  public void setBranchAddressId(String v )
>  public void setAddressRelatedByBranchAddressId(Address v)
> 
> I've tried using all three methods, however, they all end up being null
> 
> Am I missing a step here? shouldn't the primary key be available after the 
> save method or is there something else I need to do.
> 
> 
> Thanks,
> 
> Jeff Painter
> painter@kiasoft.com
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 
-- 
Michael Mainguy
(248)935-8507
mainguym@mich.com


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: old question about retrieving PrimaryKey from new object [SOLUTION]

Posted by Michael Mainguy <ma...@mich.com>.
That's pretty funny, because I've been creating tables left and right
and I have constantly remind myself to make sure the id_table values get
generated.  The way it's set up in the init target something gets
screwed up and none of my idtable rows get properly generated.  I've
been manually running the generated sql script, I didn't realize there
was an ant target that would do it... Good information!


On Wed, 2003-04-16 at 13:33, Jeffery Painter wrote:
> alright... I got so used to not running ant init I had forgotten to hit 
> my id-table... so it looks like when developing using the following 
> targets
> 
>  ant project-om 
>  ant project-sql
> 
> you should also hit the target
> 
>  ant project-id-table-init-sql
> 
> to update the idbroker entries in id_table if you create
> new tables in your project.
> 
> arg... I should have looked for this sooner ;)
> 
> 
> Thanks for the help!
> 
> Jeff Painter
> painter@kiasoft.com
> 
> 
> 
> On Wed, 16 Apr 2003, Jeffery Painter wrote:
> 
> > 
> > hmm... I added this additional table later in my project than the original 
> > elements and it looks like there is no entry in ID_TABLE for the ADDRESS 
> > table.
> > 
> > maybe I need to regenerate my sql targets :)
> > 
> > thanks for the pointer... I'll post the exact solution when I get it.
> > 
> > 
> > Jeff Painter
> > painter@kiasoft.com
> > 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 
-- 
Michael Mainguy
(248)935-8507
mainguym@mich.com



---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: old question about retrieving PrimaryKey from new object [SOLUTION]

Posted by Jeffery Painter <pa...@kiasoft.com>.
alright... I got so used to not running ant init I had forgotten to hit 
my id-table... so it looks like when developing using the following 
targets

 ant project-om 
 ant project-sql

you should also hit the target

 ant project-id-table-init-sql

to update the idbroker entries in id_table if you create
new tables in your project.

arg... I should have looked for this sooner ;)


Thanks for the help!

Jeff Painter
painter@kiasoft.com



On Wed, 16 Apr 2003, Jeffery Painter wrote:

> 
> hmm... I added this additional table later in my project than the original 
> elements and it looks like there is no entry in ID_TABLE for the ADDRESS 
> table.
> 
> maybe I need to regenerate my sql targets :)
> 
> thanks for the pointer... I'll post the exact solution when I get it.
> 
> 
> Jeff Painter
> painter@kiasoft.com
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: old question about retrieving PrimaryKey from new object

Posted by Jeffery Painter <pa...@kiasoft.com>.
hmm... I added this additional table later in my project than the original 
elements and it looks like there is no entry in ID_TABLE for the ADDRESS 
table.

maybe I need to regenerate my sql targets :)

thanks for the pointer... I'll post the exact solution when I get it.


Jeff Painter
painter@kiasoft.com



On Wed, 16 Apr 2003, Eric Emminger wrote:

> Jeffery
> 
> > I know I've read the posts many many times about returning the primary key 
> > of a newly formed base object, and I thought I had figured it all out.
> > 
> > However, I'm running into a wall with an action trying to do a complex 
> > insert of multiple objects from one form.
> > 
> > I have the following code but it is returning null for the primary keys
> > 
> > database is set to use idbroker and keys are autoincrement, mysql database
> 
> Are you sure that Address is using autoincrement, rather than inheriting 
> idbroker from the database element?
> 
> Eric
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: turbine-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Re: old question about retrieving PrimaryKey from new object

Posted by Eric Emminger <er...@ericemminger.com>.
Jeffery

> I know I've read the posts many many times about returning the primary key 
> of a newly formed base object, and I thought I had figured it all out.
> 
> However, I'm running into a wall with an action trying to do a complex 
> insert of multiple objects from one form.
> 
> I have the following code but it is returning null for the primary keys
> 
> database is set to use idbroker and keys are autoincrement, mysql database

Are you sure that Address is using autoincrement, rather than inheriting 
idbroker from the database element?

Eric


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org