66import java .time .LocalDateTime ;
77import java .time .temporal .ChronoUnit ;
88
9- import jakarta .persistence .EntityManagerFactory ;
10- import jakarta .persistence .Query ;
11- import jakarta .persistence .TypedQuery ;
12-
139import org .junit .jupiter .api .BeforeAll ;
1410import org .junit .jupiter .api .BeforeEach ;
1511import org .junit .jupiter .api .Test ;
1612
1713import info .unterrainer .commons .rdbutils .exceptions .RdbUtilException ;
1814import info .unterrainer .commons .rdbutils .jpas .TestJpa ;
15+ import jakarta .persistence .EntityManagerFactory ;
16+ import jakarta .persistence .Query ;
17+ import jakarta .persistence .TypedQuery ;
1918import lombok .extern .slf4j .Slf4j ;
2019
2120@ Slf4j
@@ -51,6 +50,21 @@ public void persistingAndReadingEntityWorks() {
5150 assertThat (jpa .getEditedOn ()).isEqualTo (testJpa .getEditedOn ().truncatedTo (ChronoUnit .MICROS ));
5251 }
5352
53+ @ Test
54+ public void persistingAndUpdatingAndReadingEntityWorks () {
55+ persistTestEntity (testJpa );
56+
57+ testJpa .setMessage ("new message" );
58+ testJpa .setCreatedOn (LocalDateTime .now ().plus (1 , ChronoUnit .SECONDS ));
59+ testJpa .setEditedOn (LocalDateTime .now ().plus (14 , ChronoUnit .SECONDS ));
60+ updateTestEntity (testJpa );
61+
62+ TestJpa jpa = selectFirstTestEntity ();
63+ assertThat (jpa .getMessage ()).isEqualTo (testJpa .getMessage ());
64+ assertEquals (jpa .getCreatedOn (), testJpa .getCreatedOn ().truncatedTo (ChronoUnit .MICROS ));
65+ assertThat (jpa .getEditedOn ()).isEqualTo (testJpa .getEditedOn ().truncatedTo (ChronoUnit .MICROS ));
66+ }
67+
5468 private int deleteTestTable () {
5569 return Transactions .withNewTransactionReturning (emf , em -> {
5670 Query q = em .createQuery (String .format ("DELETE FROM %s AS o" , TestJpa .class .getSimpleName ()));
@@ -66,6 +80,12 @@ private void persistTestEntity(final TestJpa jpa) {
6680 });
6781 }
6882
83+ private void updateTestEntity (final TestJpa jpa ) {
84+ Transactions .withNewTransaction (emf , em -> {
85+ em .merge (jpa );
86+ });
87+ }
88+
6989 private TestJpa selectFirstTestEntity () {
7090 return Transactions .withNewTransactionReturning (emf , em -> {
7191 TypedQuery <TestJpa > q = em
0 commit comments