/
githubmirror
/
ydb-java-dialects
Обзор
Документация
Войти
/
githubmirror
/
ydb-java-dialects
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
hibernate-dialect/src/test/java/tech/ydb/hibernate/exception/ExceptionConversionTest.java
53 строки
2 KB
Kirill Kurdyukov
Make hibernate6 profile Java 11 compatible (#230)
14 июл 2026, 15:53
Не верифицирован
14 июл 2026, 15:53
f78b038
Код
Авторство
О чём код?
package tech.ydb.hibernate.exception; import org.hibernate.cfg.AvailableSettings; import org.hibernate.exception.ConstraintViolationException; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; import tech.ydb.test.junit5.YdbHelperExtension; import static org.junit.jupiter.api.Assertions.assertThrows; import static tech.ydb.hibernate.TestUtils.*; class ExceptionConversionTest { @RegisterExtension private static final YdbHelperExtension ydb = new YdbHelperExtension(); @BeforeAll static void setUp() { SESSION_FACTORY = basedConfiguration() .setProperty(AvailableSettings.URL, jdbcUrl(ydb)) .setProperty(AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, "none") .addAnnotatedClass(DupTestEntity.class) .buildSessionFactory(); inTransaction(session -> { session.createNativeQuery( "CREATE TABLE exception_test_dup (" + " id Int32 NOT NULL," + " name Text," + " PRIMARY KEY (id)," + " INDEX idx_dup_name GLOBAL UNIQUE ON (name)" + ")" ).executeUpdate(); }); } @Test void duplicatePrimaryKeyThrowsConstraintViolationException() { inTransaction(session -> session.persist(new DupTestEntity(1, "pk-first"))); assertThrows(ConstraintViolationException.class, () -> inTransaction(session -> session.persist(new DupTestEntity(1, "pk-duplicate")))); } @Test void duplicateUniqueIndexThrowsConstraintViolationException() { inTransaction(session -> session.persist(new DupTestEntity(10, "unique-value"))); assertThrows(ConstraintViolationException.class, () -> inTransaction(session -> session.persist(new DupTestEntity(11, "unique-value")))); } }