Files
hibernate-demo/h8-preview/src/test/java/com/ankurm/h8/MutatingNamedQueryTest.java
T

27 lines
909 B
Java

package com.ankurm.h8;
import static org.assertj.core.api.Assertions.assertThat;
import org.hibernate.SessionFactory;
import org.junit.jupiter.api.Test;
/** A JPA @NamedQuery whose text is an UPDATE: accepted or rejected at start-up? */
class MutatingNamedQueryTest {
@Test
void recordsStartupOutcome() {
Transcript t = new Transcript("03-mutating-named-query");
String outcome;
try (SessionFactory sf = Db.open(MutatingNamedQueryEntity.class)) {
int rows = sf.fromTransaction(s -> s.createNamedQuery("Mutating.rename").setParameter("name", "x").executeUpdate());
outcome = "session factory built; createNamedQuery(..).executeUpdate() returned " + rows;
}
catch (RuntimeException ex) {
outcome = "threw " + Db.describe(ex) + " :: " + String.valueOf(Db.root(ex).getMessage()).lines().findFirst().orElse("");
}
t.line(outcome);
t.write();
assertThat(outcome).isNotBlank();
}
}