db-jdo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Craig L Russell <Craig.Russ...@Sun.COM>
Subject Re: Persisting object and foreign keys
Date Mon, 29 Jun 2009 21:43:17 GMT
Hi,

If the combo box is populated from the database, perhaps you could  
keep a detached City object around (as a value of a Map corresponding  
to the name of the city as the key) and when the new Address instance  
is created, use the detached City instance as the value of the City  
field in the new Address instance. When you do makePersistent on the  
Address, the detached City instance will be reconnected to the database.

Craig

On Jun 29, 2009, at 12:54 PM, LFS wrote:

> Hi
>
> This is my situation: I have an Address object that I
> persist/retrieve from the DB. It contains a City object, reperesenting
> the city on which that address is. City contains State, and State
> contains Country object (a long N-1 chain).
> When I'm creating a new
> address from user input, the user selected its city from a combo box
> which I populated from DB, then I'll have the city's ID.
> When I try
> to persist the new address, the most I can do is put a City object on
> it, containing only the city ID. The problem is that persisting this
> will erase the City record for that ID on the DB, because other fields
> like Name and State will be null. I want simply to set the foreign id
> on the Address object, nothing else.
>
> I believe there is some
> good solution for this... my intention is not updating the City  
> object,
> and retrieving it to put it back on the address object before being
> persisted sounds very strange and a performance nightmare.
>
> What's the proper way to do this?
>
> Thanks!
>
> Note: I'm using application identity and DataNucleus JDO.
>
>
>       
> ____________________________________________________________________________________
> Veja quais são os assuntos do momento no Yahoo! +Buscados
> http://br.maisbuscados.yahoo.com

Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!


Mime
View raw message