|
| 1 | +package org.hibernate.envers.test.integration.customtype; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | +import java.util.List; |
| 5 | + |
| 6 | +import org.hibernate.annotations.Type; |
| 7 | +import org.hibernate.engine.spi.SessionFactoryImplementor; |
| 8 | +import org.hibernate.engine.spi.SessionImplementor; |
| 9 | +import org.hibernate.envers.Audited; |
| 10 | +import org.hibernate.envers.boot.internal.EnversService; |
| 11 | +import org.hibernate.orm.test.envers.BaseEnversJPAFunctionalTestCase; |
| 12 | +import org.hibernate.orm.test.envers.Priority; |
| 13 | +import org.hibernate.persister.entity.EntityPersister; |
| 14 | +import org.hibernate.type.CustomType; |
| 15 | +import org.hibernate.usertype.UserType; |
| 16 | + |
| 17 | +import org.hibernate.testing.TestForIssue; |
| 18 | +import org.junit.Test; |
| 19 | + |
| 20 | +import jakarta.persistence.Entity; |
| 21 | +import jakarta.persistence.EnumType; |
| 22 | +import jakarta.persistence.Enumerated; |
| 23 | +import jakarta.persistence.GeneratedValue; |
| 24 | +import jakarta.persistence.Id; |
| 25 | + |
| 26 | +import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping; |
| 27 | +import static org.hibernate.testing.transaction.TransactionUtil.doInJPA; |
| 28 | +import static org.junit.Assert.assertEquals; |
| 29 | +import static org.junit.Assert.assertNull; |
| 30 | +import static org.junit.Assert.assertTrue; |
| 31 | +import java.time.Duration; |
| 32 | + |
| 33 | +@TestForIssue(jiraKey = "HHH-17243") |
| 34 | +public class DurationTest extends BaseEnversJPAFunctionalTestCase{ |
| 35 | + |
| 36 | + @Entity(name = "Duration") |
| 37 | + @Audited |
| 38 | + public static class DurationTestEntity { |
| 39 | + @Id |
| 40 | + @GeneratedValue |
| 41 | + private Integer id; |
| 42 | + |
| 43 | + private Duration duration; |
| 44 | + |
| 45 | + DurationTestEntity(){ |
| 46 | + |
| 47 | + } |
| 48 | + |
| 49 | + DurationTestEntity(Duration aDuration) { |
| 50 | + this.duration = aDuration; |
| 51 | + } |
| 52 | + |
| 53 | + public Integer getId() { |
| 54 | + return id; |
| 55 | + } |
| 56 | + |
| 57 | + public Duration getDuration() { |
| 58 | + return duration; |
| 59 | + } |
| 60 | + |
| 61 | + public void setDuration(Duration aDuration) { |
| 62 | + this.duration = aDuration; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + protected Class<?>[] getAnnotatedClasses() { |
| 68 | + return new Class<?>[] { DurationTestEntity.class }; |
| 69 | + } |
| 70 | + |
| 71 | + private Integer durationId; |
| 72 | + |
| 73 | + @Test |
| 74 | + @Priority(10) |
| 75 | + public void initData() { |
| 76 | + // Revision 1 - insert |
| 77 | + this.durationId = doInJPA( this::entityManagerFactory, entityManager -> { |
| 78 | + final DurationTestEntity duration = new DurationTestEntity(Duration.ofHours(2)); |
| 79 | + entityManager.persist( duration ); |
| 80 | + return duration.getId(); |
| 81 | + } ); |
| 82 | + |
| 83 | + // Revision 2 - update |
| 84 | + doInJPA( this::entityManagerFactory, entityManager -> { |
| 85 | + final DurationTestEntity duration = entityManager.find( DurationTestEntity.class, this.durationId ); |
| 86 | + duration.setDuration(Duration.ofHours(3)); |
| 87 | + entityManager.merge(duration); |
| 88 | + } ); |
| 89 | + } |
| 90 | +} |
0 commit comments