[jboss-user] [JBoss Seam] - unique=true attribute of primary key in generated class prev

kumlali do-not-reply at jboss.com
Sun Aug 19 19:40:31 EDT 2007


Hi,

Following steps cause "such unique or primary key already exists in the table" error. Although it smells like Hibernate Tools problem, I'm not sure whether it is directly related with Hibernate Tools or its improper usage. By the way, it may only happen in Oracle case.

Am I missing something or should I create a Jira issue for this?

Regards,

Ali Sadik Kumlali

-----------------------------

- Create PEOPLE table using following script:

 
  |     CREATE TABLE PEOPLE (
  |           "ID" NUMBER NOT NULL, 
  |           "SURNAME" VARCHAR2(50 BYTE), 
  |           "NAME" VARCHAR2(25 BYTE), 
  |       CONSTRAINT "PEOPLE_PK" PRIMARY KEY ("ID"));

- Generate entities:

c:\seam>seam generate-entities

- Annotation of primary key column(ID) found in People.java should have "unique = true" attribute:

@Id
  | @Column(name = "ID", unique = true, nullable = false, precision = 22, scale = 0)
  | @NotNull
  | public BigDecimal getId() {
  |     return this.id;
  | }
  | 
- Drop the PEOPLE table:

DROP TABLE "PEOPLE" CASCADE CONSTRAINTS;

- To force the schema to be generated from entity classes, deploy application: 

c:\seam\examples\people_sample>ant

- Dig in the server logs. You should see an error:

02:00:36,956 INFO  [SchemaExport] Running hbm2ddl schema export
  | 02:00:36,959 INFO  [SchemaExport] exporting generated schema to database
  | 02:00:37,215 ERROR [SchemaExport] Unsuccessful: create table PEOPLE (ID number(22,0) not null unique, NAME varchar2(25 char), SURNAME varchar2(50 char), primary key (ID))
  | 02:00:37,217 ERROR [SchemaExport] ORA-02261: such unique or primary key already exists in the table

-  Remove "unique=true" attribute from "@Column" annotation and compile/redeploy the application. You should see table PEOPLE is created and logs are fine.




View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4075613#4075613

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4075613



More information about the jboss-user mailing list