> But presumably the 'name' column is declared 'UNIQUE' for a reason?
> Allowing you to just add tag3 would violate the unique-ness,
> wouldn't it? If you don't really need them to be unique after all,
> shouldn't you change the table definition to reflect that?
To simplify matters I didn't explain the whole situation but I guess
this is necessary now:
Let's say we have another class, for example a "BlogEntry" class,
which contains - among other things - a Set of Tag objects. Since
there can be many BlogEntry and Tag instances I want the tags to be
unique in the database scheme. blog entries and tags are related to
each other via a join table which contains the columns "blog_id" and
"tag_id".
What I was hoping for is that JDO automatically handles the uniqueness
of tags when persisting a BlogEntry object with n Tag objects and
inserts the right ids into the join table.
Sven - 20 Dec 2007 18:24 GMT
Update: I've created a method which returns a Tag object from the
database based on a name, if available. This method detaches the Tag
object. Also the Tag class was not defined as detachable before which
I changed.
Now, when I persist a BlogEntry object which contains new and existing
Tag objects no more exception occurs, but the existing Tags are not
joined to the BlogEntry object in the join table.