|
| 1 | +package tech.ydb.hibernate.auto_inc; |
| 2 | + |
| 3 | +import org.hibernate.MappingException; |
| 4 | +import org.hibernate.cfg.AvailableSettings; |
| 5 | +import org.junit.jupiter.api.Assertions; |
| 6 | +import org.junit.jupiter.api.extension.RegisterExtension; |
| 7 | +import static tech.ydb.hibernate.TestUtils.SESSION_FACTORY; |
| 8 | +import static tech.ydb.hibernate.TestUtils.basedConfiguration; |
| 9 | +import static tech.ydb.hibernate.TestUtils.jdbcUrl; |
| 10 | +import tech.ydb.test.junit5.YdbHelperExtension; |
| 11 | + |
| 12 | +/** |
| 13 | + * @author Kirill Kurdyukov |
| 14 | + */ |
| 15 | +public class GenerationTypeIdentityTest { |
| 16 | + |
| 17 | + @RegisterExtension |
| 18 | + private static final YdbHelperExtension ydb = new YdbHelperExtension(); |
| 19 | + |
| 20 | +// @Test |
| 21 | + void serialTypesTest() { |
| 22 | + /* |
| 23 | + create table test_table_int_auto_inc ( |
| 24 | + id Serial, |
| 25 | + text Text, |
| 26 | + primary key (id) |
| 27 | + ) |
| 28 | + */ |
| 29 | + |
| 30 | + SESSION_FACTORY = basedConfiguration() |
| 31 | + .addAnnotatedClass(TestEntityInt.class) |
| 32 | + .addAnnotatedClass(TestEntityLong.class) |
| 33 | + .addAnnotatedClass(TestEntityShort.class) |
| 34 | + .setProperty(AvailableSettings.URL, jdbcUrl(ydb)) |
| 35 | + .buildSessionFactory(); |
| 36 | + |
| 37 | + Assertions.assertThrows(MappingException.class, () -> basedConfiguration() |
| 38 | + .addAnnotatedClass(TestEntityFail.class) |
| 39 | + .setProperty(AvailableSettings.URL, jdbcUrl(ydb)) |
| 40 | + .buildSessionFactory()); |
| 41 | + |
| 42 | + SESSION_FACTORY.inTransaction( |
| 43 | + session -> { |
| 44 | + var intE = new TestEntityInt(); |
| 45 | + intE.setText("test"); |
| 46 | + session.persist(intE); |
| 47 | + var intS = new TestEntityShort(); |
| 48 | + intS.setText("test"); |
| 49 | + session.persist(intS); |
| 50 | + var intL = new TestEntityLong(); |
| 51 | + intL.setText("test"); |
| 52 | + session.persist(intL); |
| 53 | + } |
| 54 | + ); |
| 55 | + } |
| 56 | +} |
0 commit comments