Update code due to upgrade to Jakarta EE 11 APIs

This commit is contained in:
Sam Brannen
2024-12-03 15:10:32 +01:00
parent 5ac0b8e22e
commit d41d674c4f
5 changed files with 17 additions and 15 deletions

View File

@@ -207,7 +207,7 @@ class DataBinderConstructTests {
}
private static class NestedDataClass {
static class NestedDataClass {
private final String param1;

View File

@@ -53,11 +53,11 @@ class HibernateNativeEntityManagerFactoryIntegrationTests extends AbstractContai
}
@Override
@Test
@Override
protected void testEntityManagerFactoryImplementsEntityManagerFactoryInfo() {
boolean condition = entityManagerFactory instanceof EntityManagerFactoryInfo;
assertThat(condition).as("Must not have introduced config interface").isFalse();
assertThat(entityManagerFactory).as("Must not have introduced config interface")
.isNotInstanceOf(EntityManagerFactoryInfo.class);
}
@Test
@@ -66,23 +66,21 @@ class HibernateNativeEntityManagerFactoryIntegrationTests extends AbstractContai
String firstName = "Tony";
insertPerson(firstName);
List<Person> people = sharedEntityManager.createQuery("select p from Person as p").getResultList();
List<Person> people = sharedEntityManager.createQuery("select p from Person as p", Person.class).getResultList();
assertThat(people).hasSize(1);
assertThat(people.get(0).getFirstName()).isEqualTo(firstName);
assertThat(people.get(0).postLoaded).isSameAs(applicationContext);
}
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testCurrentSession() {
String firstName = "Tony";
insertPerson(firstName);
Query q = sessionFactory.getCurrentSession().createQuery("select p from Person as p");
List<Person> people = q.getResultList();
assertThat(people).hasSize(1);
assertThat(people.get(0).getFirstName()).isEqualTo(firstName);
assertThat(people.get(0).postLoaded).isSameAs(applicationContext);
Query<Person> q = sessionFactory.getCurrentSession().createQuery("select p from Person as p", Person.class);
assertThat(q.getResultList()).hasSize(1);
assertThat(q.getResultList().get(0).getFirstName()).isEqualTo(firstName);
assertThat(q.getResultList().get(0).postLoaded).isSameAs(applicationContext);
}
@Test // SPR-16956

View File

@@ -56,6 +56,7 @@ class HibernateNativeEntityManagerFactorySpringBeanContainerIntegrationTests
"/org/springframework/orm/jpa/hibernate/inject-hibernate-spring-bean-container-tests.xml"};
}
@SuppressWarnings("deprecation")
private ManagedBeanRegistry getManagedBeanRegistry() {
SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class);
ServiceRegistry serviceRegistry = sessionFactory.getSessionFactoryOptions().getServiceRegistry();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,8 +48,10 @@ public class HibernatePersonRepository implements PersonRepository {
@Override
public Person findByName(String name) {
return (Person) this.sessionFactory.getCurrentSession().createQuery(
"from Person person where person.name = :name").setParameter("name", name).getSingleResult();
return this.sessionFactory.getCurrentSession()
.createQuery("from Person person where person.name = :name", Person.class)
.setParameter("name", name)
.getSingleResult();
}
}

View File

@@ -330,7 +330,7 @@ class WebExchangeDataBinderTests {
}
private static class MultipartDataClass {
static class MultipartDataClass {
private final FilePart part;
@@ -351,4 +351,5 @@ class WebExchangeDataBinderTests {
return nullablePart;
}
}
}