# hibernate-savepoint-fix **Repository Path**: mirrors_cockroachdb/hibernate-savepoint-fix ## Basic Information - **Project Name**: hibernate-savepoint-fix - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-24 - **Last Updated**: 2023-08-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## The problem The problem with Hibernate and CockroachDB that this solves is that Hibernate does not support `SAVEPOINT`. This is a problem, because Cockroach [ab]uses the SQL syntax for `SAVEPOINT` to allow for transaction retries. The core problem comes down to the fact that Hibernate assumes that once a transaction has failed, it will not be started again, whereas in Cockroach we can run `ROLLBACK TO SAVEPOINT...` to retry. The fix is to replace the Hibernate class that disallows this with one that allows it. ## What to do There are two files in this repo, `CockroachDBTransactionCoordinator.java`, and `CockroachDBTransactionCoordinatorBuilder.java` which can be included in a Hibernate project to accomplish this. To install them, but them in the repo under a path like `src/main/java/com/cockroachlabs` and add the following config to the `hibernate.cfg.xml`: ```xml com.cockroachlabs.CockroachDBTransactionCoordinatorBuilder ``` Then they should be able to successfully run queries like ```java session.createNativeQuery("ROLLBACK TO SAVEPOINT COCKROACH_RESTART").executeUpdate(); ``` in the case of an error.