> Unique index or primary key violation: "MYTABLE_DATA ON
> PUBLIC.MYTABLE(ID, CREATEDAT, ..., ...)"
The problem is that there was a primary key violation. I agree it's a
weird error message, I will fix that in the next release. However,
it's definitely a primary key violation. Here is a test case that
throws a similar exception:
DROP TABLE IF EXISTS TEST;
CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255));
INSERT INTO TEST VALUES(1, 'Hello');
INSERT INTO TEST VALUES(1, 'World');
-- Unique index or primary key violation: "TEST_DATA ON PUBLIC.TEST(ID, NAME)"
> Is my database corrupt like suggested here: http://fri13th.com/blog/archives/285
No. This blog article is quite old (2007). There were a lot of changes
in H2 since then. And this error message is not related to corruption.
Regards,
Thomas
> @GeneratedValue(strategy = GenerationType.TABLE)
This seems to be a relatively common problem (at least I found others
get similar problems by doing a Google search).
> But why a different message occur for other ('normal') cases?
> Is it different because the primary key (MYTABLE.ID) instead of the
> additional unique constraint (on MYTABLE.NAME) is violated?
The problem is (warning: technical details ahead), if you have a
single column primary key, and the data type is INT, BIGINT, or
similar, then there is no actual index created. Instead, the "main"
lookup method of the table is used (which is also a b-tree structure,
like regular indexes, but it uses different class and storage format:
class PageDataIndex instead of PageBtreeIndex). That's where the
"_DATA" comes from in the error message. There is always a
PageDataIndex even if there is no primary key, so the database is
re-using that if possible. but unfortunately it's also re-using the
name of that object in the error message, which is wrong. This is what
I will fix. Other databases call this a "clustered index" by the way:
http://en.wikipedia.org/wiki/Index_%28database%29#Clustered
Regards,
Thomas