Beginner question about JDO best practice



Dear all,

this is the first time I'm using JDO/ORM (the JPOX implementation) and
so have a question about best practice.

Let's assume we have a class "Tag" with the only property "String
name" and according setters and getters. The related table has two
columns "PRIMARY BIGINT tag_id" and "UNIQUE VARCHAR name". Note that
the column "name" is unique.

Let's further assume that we manually create some Tag objects during
application runtime. We now want to persist these objects but we don't
care if they are already persisted in the database. If this is the
case, JDO should just attach the object to the database instance. What
is the best practice to accommodate this? Do I have to manually check
every object for existence first? I would like to avoid this.

Let's say the tag "coffee" is already available in the database. I'm
looking for something which works like this:

--8<-snip->8--

Tag tag1 = new Tag( "java" );
Tag tag2 = new Tag( "means" );
Tag tag3 = new Tag( "coffee" );

// no problem
pm.makePersistent( tag1 );

// no problem
pm.makePersistent( tag2 );

// throws SQLException DUPLICATE KEY but should just attach/update
tag3 to database instance
pm.makePersistent( tag3 );

--8<-snip->8--

Thanks for any hint!
.



Relevant Pages

  • Re: Beginner question about JDO best practice
    ... this is the first time I'm using JDO/ORM and ... so have a question about best practice. ... JDO should just attach the object to the database instance. ... tag3 to database instance ...
    (comp.lang.java.databases)
  • CHIKARA Press Release
    ... For the first time in company history, two masked men put their idenitities on the line, in a bout that will serve as the ... After 104 minutes and change, Chris Hero's assassin, Gran Akuma, emerged victorious. ... The winner of this match will be entered into the Tag World Grand Prix 2006 with a partner of his choosing. ... Mister ZERO vs. Rorschach ...
    (rec.sport.pro-wrestling)
  • Re: Page centered in IE7 but not in FF2.0
    ... It is also not a good idea to use "tag words" as names. ... You give advice on HTML in public but cannot even ... css, then it could be said that they are equally informed by the ... If best practice was used and the class was based on need to so ...
    (alt.html)
  • Re: This Effin Sucks!
    ... Turby writes: ... tag along behind me with a helmet cam would be very nice though. ... Practice is the only way I expect to really learn. ...
    (rec.motorcycles)
  • Re: in a column of numbs and names, put the numbs in other colum
    ... The first time I tried your suggestion within my file and I believe because ... the scanned data file, ... Can anyone tell me if I can edit the ... The tag # into another column. ...
    (microsoft.public.excel.newusers)