Hi all,

I’m working on a Cayenne issue 
(https://issues.apache.org/jira/browse/CAY-2137). To be able to create a test 
for the fix, I think I have to create a new cayenne testing project inside 
cayenne-server (to have a map and some entities to test on). I’ve done that and 
have gotten everything to work, apart from the SQL generation part. When the 
test is fired up, it will attempt to generate the schema for my map by 
generating and running the following SQL-statements

— CREATE CACHED TABLE invoice (invoice_number INTEGER NOT NULL, year INTEGER 
NOT NULL, PRIMARY KEY (invoice_number, year))
— CREATE CACHED TABLE invoice_line (invoice_number INTEGER NOT NULL, 
line_number INTEGER NOT NULL, year INTEGER NOT NULL, PRIMARY KEY 
(invoice_number, line_number, year))
— ALTER TABLE invoice_line ADD CONSTRAINT U_invoice_line_16819552 FOREIGN KEY 
(year, invoice_number) REFERENCES invoice (year, invoice_number) ON DELETE 
CASCADE

But the last line will fail with the following exception:
— java.sql.SQLException: Primary or unique constraint required on main table: 
INVOICE in statement [ALTER TABLE invoice_line ADD CONSTRAINT 
U_invoice_line_16819552 FOREIGN KEY (year, invoice_number) REFERENCES invoice 
(year, invoice_number) ON DELETE CASCADE]

This is reproducible in other projects using HSQLDB—and generating the schema 
from the same map in H2 works fine, so it seems it might be a problem with 
HSQLDB schema creation. But I’ve not seen in what way the schema generation is 
wrong, one would think just declaring the primary key columns should be enough, 
which cayenne is certainly doing.

If anyone cares to take a look, here’s a quick maven project that contains the 
model in question and demonstrates the problem (configurations for both H2 and 
HSQLDB).

https://github.com/hugith/rel-test/

Cheers,
- hugi

Reply via email to