Wednesday, November 12, 2008

Seam-gen and Oracle Express

I installed Oracle Express.  I created a user, "local," with the creative password, "local."  I created a project with seam-gen.  I created an entity object and annotated the id column with :
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id", unique = true, nullable = false)
private Long id;
On deploy I saw in the logs :
09:42:14,281 INFO  [SchemaExport] exporting generated schema to database
09:42:14,609 ERROR [SchemaExport] Unsuccessful: create table TABLE_NAME (id number(19,0) not null unique, name varchar2(30) not null, description varchar2(200) not null, inputChannel varchar2(100) not null, outputChannel varchar2(100) not null, parser varchar2(100), primary key (id))
09:42:14,609 ERROR [SchemaExport] ORA-02261: such unique or primary key already exists in the table
The message, "such unique or primary key already exists in the table," led me to believe that the table existed.  However, I couldn't see it using the Oracle web interface.  Or SQL Developer.  Or MyEclipse. 

So I ran the statement in the web interface.  Same error. 

The problem turned out to be that the statement was creating the id twice.  First with, "id number(19,0) not null unique," and second with, "primary key (id)."

I changed the syntax, and it worked.  As for the annotations, I removed the "Column" annotation :
@Column(name = "id", unique = true, nullable = false)
When I redeployed it worked fine.

The working annotation was :
@Id
@SequenceGenerator(name = "TABLE_NAME_SEQUENCE_GENERATOR", sequenceName = "TABLE_NAME_SEQUENCE")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TABLE_NAME_SEQUENCE_GENERATOR")
private Long id;

No comments: