[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.technology.jsr220-orm] Re: Are alternate keys supported?

Hi John,

Ok, now I understand.

You can use the Generator type "Auto" to achieve the same affect as the
Hibernate "native" generator type.  This simply sets the id generation to
the type supported by the underlying database.

Also, if you use a composite primary key and idenitify your firstName and
surName as identity fields, then we will ensure uniqueness across all three
columns.    We will look to support the "unique" attribute of the column
annotation when we integrate with the new DTP code base.   Then we will
generate the DDL that will validate the first/sur name uniqueness
independent of the PK uniqeness.   Given our current direction, this will be
sometime after the new year.

Robert Greene
JSR220-ORM team lead
rgreene@xxxxxxxxxxx


"John Cage" <ahanys@xxxxxxxxx> wrote in message
news:6496d2ab952b6cec0a17b23520f278ee$1@xxxxxxxxxxxxxxxxxx
> Hi,
>
> when I create a class User like this with geters and setters.
> public class User {
>     private Long id;
>     private String firstName;
>     private String surName;
>     ...
> }
>
> and I want this:
> -attribute "id" will have "native" generator type for Hibernate.
>
> And I want that database will control uniqueness for (firstName, surName)
> pairs = this is alternate key for database. I want this: "database will
> control duplicate entyties" for this 2 column key.
>
> so when I create new User {firstName='mark' surName='spencer'} then I
> persist this object. And when I do this for second time, database will
> throw an exception. This is correct behaviour.
>
> I want put this information about alternate keys into the class design(via
> eclipse tool) and when I run generate DDL script from JAVA classes this
> alternate key handling statements will be put into .sql create table
> statement.
>
>
> example:
>
> create table User {
>    int id primary key,
>    varchar(20) firstName,
>    varchar(20) surName,
>    unique (firstName, surName)
> }
>
>
>
> This clause "unique (firstName, surName)" is alternate key handling. This
> is done in database.
>
> Thanks,
> John Cage
>