hibernate-reactive icon indicating copy to clipboard operation
hibernate-reactive copied to clipboard

No access to ConstraintViolationException.constraintName

Open borellda opened this issue 3 years ago • 3 comments

Hello Hibernate team,

I'm migrating an existing app to Quarkus and I want also to use Hibernate reactive. Quarkus platform version is: 2.11.1.Final In the current dependency pulled in: org.hibernate.reactive:hibernate-reactive-core:1.1.7.Final, it seems there is no access to the "constraintName" property of ConstraintViolationException class. Is this on purpose, then how can I check the reason of the violation. Could you please have a look?

Regards, Daniel

borellda avatar Aug 03 '22 14:08 borellda

You are right, we don't extract the code from the error message. Right now you need to parse the error message if you want to extract the constraint name.

For future reference, at the moment the error message for Postgres is:

org.hibernate.HibernateException: io.vertx.pgclient.PgException: ERROR: duplicate key value violates unique constraint "uk_ddwji91nxj43borrm1ii72th8" (23505)

On top of this, we don't seem to throw the right exception when there is a constraint violation. We should throw a ConstraintViolationException but we throw a generic HibernateException. It's possible to see this via MutinyExceptionsTest.

I've only given this a quick look though. We should probably wait until the integreation with ORM 6 is done.

DavideD avatar Aug 03 '22 15:08 DavideD

Thank you @DavideD for the very quick reply. Didn't mention we are using Oracle, but I guess the message will be similar and I can deal with it.

Maybe worth to open another issue to track the Exception type issue, this seems to be more serious?

Best regards.

borellda avatar Aug 04 '22 06:08 borellda

This was something I discusses with @tsegismont on the train one day recently.

Basically, the whole exception mapping stuff in Hibernate (IIRC) is currently unimplementable in HR because the SQL client doesn't expose the error codes we would need to implement that.

So this is actually bigger problem (really a missing feature).

I believe there is now issue open against the Vert.x client.

gavinking avatar Aug 04 '22 12:08 gavinking

The SQL state or vendor error code are now accessible from the exception

DavideD avatar Nov 29 '23 15:11 DavideD