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: ordered lists vs unordered lists
    ... It is a specialist tag that authors should use to ... practice the browser did not generate either the numbers or some other ... make use of the ol tag to convey the idea of the meaning. ... It is good practice. ...
    (alt.html)
  • 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: Zebra striped list
    ... This isn't the first time I've made a list with zebra striped lists. ... tag I'd rather class them all. ... Javascript solutions are often quite good for this sort of thing. ...
    (uk.net.web.authoring)