Beginner question about JDO best practice
- From: Sven <sj1981@xxxxxxxxx>
- Date: Thu, 20 Dec 2007 05:26:19 -0800 (PST)
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!
.
- Follow-Ups:
- Re: Beginner question about JDO best practice
- From: Dyreatnews
- Re: Beginner question about JDO best practice
- Prev by Date: Re: Global temporary tables in Java DB -- Apache Derby
- Next by Date: Re: What does everyone else do for graphically displaying data?
- Previous by thread: Openwave Hiring Indian Professional for H1B
- Next by thread: Re: Beginner question about JDO best practice
- Index(es):
Relevant Pages
|
|