Hello,
I need to implement a many-to-many association with some association attributes. Therefore I found this tutorial:
http://boris.kirzner.info/blog/archives ... osite-key/I understood, what the author is doing, but it doesn't work in my case. The tables product and item are created and both are filled with my objects. The table product_item could not even be created because DB2 tells me, that a primary key may not be NULL. However I set both IDs to nullable = false. Here is the whole errormessage:
Code:
07.04.2011 16:05:59 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: Running hbm2ddl schema export
07.04.2011 16:05:59 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: exporting generated schema to database
07.04.2011 16:06:00 org.hibernate.tool.hbm2ddl.SchemaExport create
SCHWERWIEGEND: Unsuccessful: create table product_item (item_id integer, product_id integer, primary key (item_id, product_id))
07.04.2011 16:06:00 org.hibernate.tool.hbm2ddl.SchemaExport create
SCHWERWIEGEND: DB2 SQL Error: SQLCODE=-542, SQLSTATE=42831, SQLERRMC=ITEM_ID, DRIVER=4.9.78
07.04.2011 16:06:00 org.hibernate.tool.hbm2ddl.SchemaExport create
SCHWERWIEGEND: Unsuccessful: alter table product_item add constraint FK3C742463F24F48C9 foreign key (item_id) references item
07.04.2011 16:06:00 org.hibernate.tool.hbm2ddl.SchemaExport create
SCHWERWIEGEND: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2ADMIN.PRODUCT_ITEM, DRIVER=4.9.78
07.04.2011 16:06:00 org.hibernate.tool.hbm2ddl.SchemaExport create
SCHWERWIEGEND: Unsuccessful: alter table product_item add constraint FK3C742463253F490B foreign key (product_id) references product
07.04.2011 16:06:00 org.hibernate.tool.hbm2ddl.SchemaExport create
SCHWERWIEGEND: DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704, SQLERRMC=DB2ADMIN.PRODUCT_ITEM, DRIVER=4.9.78
07.04.2011 16:06:00 org.hibernate.tool.hbm2ddl.SchemaExport execute
INFO: schema export complete
Anybody an idea?
Thanks in advance!
Stefan
PS: This is the error description from IBM:
Code:
-542
column-name CANNOT BE A COLUMN OF A PRIMARY KEY, A UNIQUE CONSTRAINT, OR A PARENT KEY BECAUSE IT CAN CONTAIN NULL VALUES
Explanation
A column that is identified in a PRIMARY KEY, a UNIQUE constraint clause, or a parent key (through a REFERENCES clause) is defined to allow null values. Null values are not permitted for these keys and clauses.
System action
The statement cannot be processed.
Programmer response
In the case of a column identified in a PRIMARY KEY or a UNIQUE constraint clause, correct the statement and resubmit it.
In the case of a column identified in a REFERENCES clause:
Drop the parent table.
Recreate it with referenced columns defined as NOT NULL.
Resubmit the statement.
SQLSTATE
42831
Parent topic: SQL error codes