New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
h2 does not correctly report the name of a violated unique constraint #4021
Comments
i have the same issue but it seems like it orignates from not even setting the constraint name in the DDL hibernate generates: |
IMHO, this is not the case, because constraint name is out there: H2 reports unique key violation by using index name, not a constraint name. The reason being, that it might be no corresponding constraint at all. Nevertheless, if index was created automatically from the constraint, then it's name would bear a constraint name in it, followed by "_INDEX_"... |
But that makes no sense from the perspective of the user. The user created a constraint named
Yes, I know that. And that's ... bad. From my perspective as a user, it makes interpreting and handling errors from JDBC more difficult, for no benefit.
This is an implementation detail which I as a user just don't care about. I want to stay at the level of abstraction I'm working at. If it were only a matter of the |
The
Of course, if you don't specify a name of the unique key, then Hibernate has to invent one for you. |
The two DDL versions my colleague @lorenzbaier reported were generated by the same client code but different hibernate and H2 versions. We looked for a reason why we were not able to see the constraint name any more, which is why we stumbled over this issue. |
The only correct way to get a constraint name from an index name in H2 is to query Note: the same index may be used by multiple constraints, so a query with filter conditions on index name can return multiple rows. Hypothetically we can try to report names of constrains instead, but indexes and constraints have different namespaces. It means we'll need to throw these exceptions with different error codes, one for violation of indexes used by constraints and another one for unique indexes without constraints. |
So, I was able to determine the versions that generated the statements above: |
@fheck So it's correct in the latest release then. |
@gavinking is there a changelog which reports this new behaviour of hibernate not generating the constraint names anymore? |
There is no such "new behavior". I mean, in the original description of this issue I show DDL generated by Hibernate, clearly containing the constraint name. |
@gavinking but the auto generated constraint names are obviously missing and i do not want to explicitly state them all |
I really don't know what you're asking about, since it's clear that Hibernate DDL generation is respecting all user-specified constraint names. And I don't know why you think the issue tracker for h2 is the appropriate place to discuss this. Hibernate has a user forum for questions about Hibernate. |
i created an issue on hibernate https://hibernate.atlassian.net/browse/HHH-17921 |
Given:
A violation of the unique constraint is reported as:
But
PUBLIC.COUNT_NAME_KEY_INDEX_2
is not the name of the constraint, it's a database-generated name. The name of the constraint iscount_name_key
.I saw in another issue here that Hibernate was blamed for not correctly extracting the constraint name from h2 messages, but Hibernate cannot possibly extract the constraint name, because it is not contained in the message.
The text was updated successfully, but these errors were encountered: