add test for StatelessSession.upsert()

This commit is contained in:
Gavin King 2023-06-23 19:32:30 +02:00
parent 1797a9196e
commit 1603e4a472
2 changed files with 46 additions and 1 deletions

View File

@ -199,7 +199,7 @@ public class StatelessSessionTest {
scope.inStatelessTransaction(
statelessSession -> {
Paper p2 = (Paper) statelessSession.get( Paper.class, paper.getId() );
Paper p2 = statelessSession.get( Paper.class, paper.getId() );
p2.setColor( "White" );
statelessSession.update( p2 );
}

View File

@ -0,0 +1,45 @@
package org.hibernate.orm.test.stateless;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.junit.jupiter.api.Test;
import static org.junit.Assert.assertEquals;
@SessionFactory
@DomainModel(annotatedClasses = UpsertTest.Record.class)
public class UpsertTest {
@Test void test(SessionFactoryScope scope) {
scope.inStatelessTransaction(s-> {
s.upsert(new Record(123L,"hello earth"));
s.upsert(new Record(456L,"hello mars"));
});
scope.inStatelessTransaction(s-> {
assertEquals("hello earth",s.get(Record.class,123L).message);
assertEquals("hello mars",s.get(Record.class,456L).message);
});
scope.inStatelessTransaction(s-> {
s.upsert(new Record(123L,"goodbye earth"));
});
scope.inStatelessTransaction(s-> {
assertEquals("goodbye earth",s.get(Record.class,123L).message);
assertEquals("hello mars",s.get(Record.class,456L).message);
});
}
@Entity
static class Record {
@Id Long id;
String message;
Record(Long id, String message) {
this.id = id;
this.message = message;
}
Record() {
}
}
}