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

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