You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by gilbertoca <gi...@gmail.com> on 2009/09/09 23:29:33 UTC
[Modeler] DbEntity:Primery Key:PK Generation Strategy - Is there
any option for natural primary key?
Hi again,
In my model I have two tables with very simple structure:
CREATE TABLE TipoVeiculo (fabricante varchar(50) NULL,
modelo varchar(20) NULL,
tipo varchar(20) NOT NULL,
PRIMARY KEY (tipo));
CREATE TABLE Veiculo (cd_cliente integer NOT NULL,
cd_tabela_preco integer NOT NULL,
cor varchar(20) NULL,
placa varchar(20) NOT NULL,
tipo varchar(20) NOT NULL, PRIMARY
KEY (placa));
VeĆculo (Vehicle)
Tipo (Vehicle Type)
So, as you can see both uses natural key. When choosing DbEntity:Primery
Key:->"PK Generation Strategy" I can't see any option for natural key!
Other thing, is this one[1] the unique way to create a getter or setter for
primary keys in the generate Java classes? I was looking for an option on
ObjEntity->attributes tab->tool bar, something like "Expose Primary Key".
Regards,
Gilberto
[1]http://cwiki.apache.org/confluence/display/CAY/Mapping+Primary+Keys
--
View this message in context: http://www.nabble.com/-Modeler--DbEntity%3APrimery-Key%3APK-Generation-Strategy---Is-there-any-option-for-natural-primary-key--tp25373490p25373490.html
Sent from the Cayenne - User mailing list archive at Nabble.com.
Re: [Modeler] DbEntity:Primery Key:PK Generation Strategy - Is there
any option for natural primary key?
Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 10/09/09 10:37 PM, gilbertoca wrote:
> Are you saying that even though my table has the primary key - it doesn't
> matter natural or surrogate key - cayenne won't ensure that it is unique?
If you are creating your own keys, it is your responsibility to create a way to generate unique keys. This is the expected behaviour: you either use Cayenne or the db to guarantee you unique keys, or it is up to you to find a way to ensure they are unique. If this is a user enterable field, you could use Cayenne's validation API to help catch the problem, or you could try to catch the db error you get when you commit. Either way you need to be aware of how this works in a threaded multi-user environment.
> One more question. While creating my DbEntities I didn't see an option for
> Unique Key Constraint. Is it a manual task?
Correct. Cayenne modeler does not currently manage database indexing.
Ari
--
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A
Re: [Modeler] DbEntity:Primery Key:PK Generation Strategy - Is there
any option for natural primary key?
Posted by Michael Gentry <mg...@masslight.net>.
Hi Gilberto,
If you are creating a brand new database (not reverse engineering an
existing database), I **strongly** recommend that you do not use
natural primary keys. There are many reasons to not use natural
primary keys and only one good one that I can think of (you have an
existing legacy database you have to support).
mrg
On Thu, Sep 10, 2009 at 8:37 AM, gilbertoca<gi...@gmail.com> wrote:
> Oh my God, I've forgot to mention that I modeling[1] and not doing reverse
> engineer from a existent database.
Re: [Modeler] DbEntity:Primery Key:PK Generation Strategy - Is
there any option for natural primary key?
Posted by gilbertoca <gi...@gmail.com>.
Aristedes Maniatis-2 wrote:
>
> I don't think using meaningful primary keys is something we want to
> encourage so much that we put a checkbox in the GUI for it.
>
Where did you see this intention in my question?
Aristedes Maniatis-2 wrote:
>
> The alternative method of creating them is easy enough.
>
So, what is the difference?
Aristedes Maniatis-2 wrote:
>
> You don't need a PK generation strategy since, as the page you reference
> states, you just need to put data in the PK field before you commit the
> object.
>
Again, where did you see this intention in my question? I don't think we are
talking the same thing.
Oh my God, I've forgot to mention that I modeling[1] and not doing reverse
engineer from a existent database.
I think
DbEntity:Primery Key:->"PK Generation Strategy" is the option I have to tel
cayenne modeler not generate any pk strategy for my table. The existent
options [Default, Database-Generated and Custom Sequence] are strategies,
but I don't want anyone! I have other alternative in Generate DB
Schema:Options->Create PK Support, but it is for all my tables and I have
only two tables with natural key.
Aristedes Maniatis-2 wrote:
>
> It is up to you to ensure that it is unique, deal with threading and
> collisions.
>
Are you saying that even though my table has the primary key - it doesn't
matter natural or surrogate key - cayenne won't ensure that it is unique?
One more question. While creating my DbEntities I didn't see an option for
Unique Key Constraint. Is it a manual task?
Thanks for you attention,
Gilberto
[1]http://www.nabble.com/-modeler--Generate-Database-Schema-doesn%27t-generate-every-relationship-to25276867.html
--
View this message in context: http://www.nabble.com/-Modeler--DbEntity%3APrimery-Key%3APK-Generation-Strategy---Is-there-any-option-for-natural-primary-key--tp25373490p25382559.html
Sent from the Cayenne - User mailing list archive at Nabble.com.
Re: [Modeler] DbEntity:Primery Key:PK Generation Strategy - Is there
any option for natural primary key?
Posted by Aristedes Maniatis <ar...@maniatis.org>.
On 10/09/09 7:29 AM, gilbertoca wrote:
> So, as you can see both uses natural key. When choosing DbEntity:Primery
> Key:->"PK Generation Strategy" I can't see any option for natural key!
> Other thing, is this one[1] the unique way to create a getter or setter for
> primary keys in the generate Java classes? I was looking for an option on
> ObjEntity->attributes tab->tool bar, something like "Expose Primary Key".
I don't think using meaningful primary keys is something we want to encourage so much that we put a checkbox in the GUI for it. The alternative method of creating them is easy enough.
You don't need a PK generation strategy since, as the page you reference states, you just need to put data in the PK field before you commit the object. It is up to you to ensure that it is unique, deal with threading and collisions.
Ari Maniatis
-------------------------->
Aristedes Maniatis
GPG fingerprint CBFB 84B4 738D 4E87 5E5C 5EFA EF6A 7D2E 3E49 102A