Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Duplicate
-
1.2.2
-
None
-
OpenJPA 1.2.2
HSQL 1.8.0.10 and HSQL 1.8.1.1 and 2.0.0-rc8
Mac OS X 10.6.2
Java 1.6.0_17 Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01-101, mixed mode)
Description
In my unit tests, I'm using the openjpa.jdbc.SynchronizeMappings feature to have OpenJPA create the schema in an HSQL in-memory database. Two of the tables in my schema each have a unique constraint that lists the same column names (foo,bar) in the same order. The generated name for both constraints is UNQ_foobar. HSQL apparently puts the names of unique constraints into a schema-wide namespace which causes the CREATE TABLE statement for the second table to fail with "constraint already exist".
@Entity
@Table( uniqueConstraints = { @UniqueConstraint( columnNames =
public class X {
...
private String foo;
private long bar;
...
}
@Entity
@Table( uniqueConstraints = { @UniqueConstraint( columnNames = { "foo", "bar" }
) } )
public class Y
[code=-60, state=S0011]
Note that I tweaked my sample code and log trace a little to simplify the test case.
I didn't try to reproduce this with OpenJPA 2.0.0 yet. From looking at the code in the 2.0.0 trunk, I can tell that this part has been rewritten completely and this issue might not apply to 2.0.0. I also don't know whether HSQL is violating the SQL standard by requiring unique constaint names to be schema-unique, not just table-unique.
What works for me as a workaround is to reorder the columns in the constraint on the second table.
Assuming this is not a bug in HSQL and assuming it also reproduces in 2.0.0 beta, I'd naively prefix constraint names with the table name but I'm no specialist in either SQL or JPA ...
Attachments
Issue Links
- duplicates
-
OPENJPA-1165 Two unique constraints in a table try to share the same constraint name
- Closed