> Again, I am not convinced that we need it. Consider what would such
> check do in case it finds a duplicate. Throw an exception? Well, this
> is what will happen anyway if you try to commit a duplicate key. So I
> don't see value in this feature.
I think that a PKViolatedException would be nice. Better than find the
message in a RuntimeException. :)
Ok, maybe the key feature is not the automatic PK checking but a way to
query the DataObjects that was not commited :)
Regards,
Leonardo.
********************
Leonardo R. Nunes
Sumersoft Tecnologia
http://www.sumersoft.com
-----Original Message-----
From: Andrus Adamchik [mailto:andru..bjectstyle.org]
Sent: sábado, 22 de novembro de 2003 18:39
To: cayenne-use..bjectstyle.org
Subject: Re: Violation of PRIMARY KEY constraint
I am still not convinced that this is something Cayenne should care
about. See below.
On Nov 22, 2003, at 5:22 PM, Leonardo R. Nunes wrote:
> Humm ... so ... I'll need to create a cache for the new objects then.
> I'll need do that because if I create one DataObject1 and before
commit
> this DataObject1 create a DataObject2 with the same PK (Example: a
> driver's license number) I'll get a SQLException.
If you are assigning primary keys yourself in the application, you
better implement some algorithm that generates unique ids following
certain rules (this seems the most appropriate approach to me in case
of drivers licenses at least). E.g. something that this class does:
http://objectstyle.org/cayenne/api/cayenne/org/objectstyle/cayenne/
util/IDUtil.html
Taking a random number and then checking the database and memory to see
if it is not used doesn't seem like a good solution to this problem. Or
you can turn this problem around if using the id in a read-only fashion
is acceptable (as it should be in most of PK cases), and use Cayenne to
generate sequential ids for you. See item (1) in this message for
suggestions on how to implement a "getID()" method:
http://objectstyle.org/cayenne/lists/cayenne-user/2003/11/0068.html
> I think that one kind of automatic PK checking would be a nice feature
> in Caynenne.
Again, I am not convinced that we need it. Consider what would such
check do in case it finds a duplicate. Throw an exception? Well, this
is what will happen anyway if you try to commit a duplicate key. So I
don't see value in this feature.
Andrus
This archive was generated by hypermail 2.0.0 : Sat Nov 22 2003 - 16:59:33 EST