Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Databases > Beginner questi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 3621 of 3876
Post > Topic >>

Beginner question about JDO best practice

by Sven <sj1981@[EMAIL PROTECTED] > Dec 20, 2007 at 05:26 AM

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!
 




 4 Posts in Topic:
Beginner question about JDO best practice
Sven <sj1981@[EMAIL PR  2007-12-20 05:26:19 
Re: Beginner question about JDO best practice
Dyreatnews@[EMAIL PROTECT  2007-12-20 16:02:48 
Re: Beginner question about JDO best practice
Sven <sj1981@[EMAIL PR  2007-12-20 07:53:41 
Re: Beginner question about JDO best practice
Sven <sj1981@[EMAIL PR  2007-12-20 10:24:46 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Dec 3 22:39:05 CST 2008.