update some of the tests to use non-deprecated methods

or at least suppress the warnings
This commit is contained in:
Gavin King 2022-01-05 13:14:12 +01:00
parent 261ca55b0f
commit 1beabbdf40
10 changed files with 153 additions and 122 deletions

View File

@ -11,7 +11,6 @@ import org.hibernate.testing.orm.domain.contacts.Contact;
import org.hibernate.testing.orm.domain.contacts.Contact.Name;
import org.hibernate.testing.orm.junit.DialectFeatureChecks;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.RequiresDialectFeature;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
@ -33,9 +32,9 @@ public class InsertUpdateTests {
public void testUpdate(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery("update Ticket set subject = 'Outage', details = 'The service is down' where id = 1").executeUpdate();
session.createQuery("update Ticket t set t.subject = 'Outage' where t.id = 1").executeUpdate();
session.createQuery("update Ticket t set t.subject = upper(t.subject) where t.id = 1").executeUpdate();
session.createStatement("update Ticket set subject = 'Outage', details = 'The service is down' where id = 1").executeUpdate();
session.createStatement("update Ticket t set t.subject = 'Outage' where t.id = 1").executeUpdate();
session.createStatement("update Ticket t set t.subject = upper(t.subject) where t.id = 1").executeUpdate();
}
);
}
@ -44,7 +43,7 @@ public class InsertUpdateTests {
public void testUpdateSecondaryTable(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery("update Contact set birthDay = local date").executeUpdate();
session.createStatement("update Contact set birthDay = local date").executeUpdate();
}
);
}
@ -53,7 +52,7 @@ public class InsertUpdateTests {
public void testUpdateEmbedded(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery("update Contact set name.first = 'Hibernate'").executeUpdate();
session.createStatement("update Contact set name.first = 'Hibernate'").executeUpdate();
}
);
}
@ -62,8 +61,8 @@ public class InsertUpdateTests {
public void testDelete(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery("delete from Ticket where id = 1").executeUpdate();
session.createQuery("delete from Ticket t where t.id = 1").executeUpdate();
session.createStatement("delete from Ticket where id = 1").executeUpdate();
session.createStatement("delete from Ticket t where t.id = 1").executeUpdate();
}
);
}
@ -77,7 +76,7 @@ public class InsertUpdateTests {
contact.setName( new Name("Hibernate", "ORM") );
contact.setBirthDay( LocalDate.now() );
session.persist(contact);
session.createQuery("delete from Contact").executeUpdate();
session.createStatement("delete from Contact").executeUpdate();
}
);
}
@ -86,8 +85,8 @@ public class InsertUpdateTests {
public void testInsertValues(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery("delete from Ticket").executeUpdate();
session.createQuery("insert into Ticket (id, key, subject, details) values (6, 'ABC123', 'Outage', 'Something is broken')").executeUpdate();
session.createStatement("delete from Ticket").executeUpdate();
session.createStatement("insert into Ticket (id, key, subject, details) values (6, 'ABC123', 'Outage', 'Something is broken')").executeUpdate();
}
);
}
@ -97,8 +96,8 @@ public class InsertUpdateTests {
public void testInsertMultipleValues(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery("delete from Ticket").executeUpdate();
session.createQuery("insert into Ticket (id, key, subject, details) values (2, 'XYZ123', 'Outage', 'Something is broken'), (13, 'HIJ456', 'x', 'x')").executeUpdate();
session.createStatement("delete from Ticket").executeUpdate();
session.createStatement("insert into Ticket (id, key, subject, details) values (2, 'XYZ123', 'Outage', 'Something is broken'), (13, 'HIJ456', 'x', 'x')").executeUpdate();
}
);
}
@ -107,9 +106,9 @@ public class InsertUpdateTests {
public void testInsertSelect(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery("delete from Ticket").executeUpdate();
session.createQuery("insert into Ticket (id, key, subject, details) select 6, 'ABC123', 'Outage', 'Something is broken'").executeUpdate();
session.createQuery("insert into Ticket (id, key, subject, details) select 13, 'DEF456', tt.subject, tt.details from Ticket tt").executeUpdate();
session.createStatement("delete from Ticket").executeUpdate();
session.createStatement("insert into Ticket (id, key, subject, details) select 6, 'ABC123', 'Outage', 'Something is broken'").executeUpdate();
session.createStatement("insert into Ticket (id, key, subject, details) select 13, 'DEF456', tt.subject, tt.details from Ticket tt").executeUpdate();
}
);
}
@ -118,9 +117,9 @@ public class InsertUpdateTests {
public void testAliasedInsertSelect(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery("delete from Ticket").executeUpdate();
session.createQuery("insert into Ticket t (t.id, t.key, t.subject, t.details) select 12, 'ABC123', 'Outage', 'Something is broken'").executeUpdate();
session.createQuery("insert into Ticket as t (t.id, t.key, t.subject, t.details) select 5, 'DEF456', tt.subject, tt.details from Ticket tt").executeUpdate();
session.createStatement("delete from Ticket").executeUpdate();
session.createStatement("insert into Ticket t (t.id, t.key, t.subject, t.details) select 12, 'ABC123', 'Outage', 'Something is broken'").executeUpdate();
session.createStatement("insert into Ticket as t (t.id, t.key, t.subject, t.details) select 5, 'DEF456', tt.subject, tt.details from Ticket tt").executeUpdate();
}
);
}

View File

@ -33,7 +33,7 @@ public class InsertWithSubSelectTest {
public void testInsert(SessionFactoryScope scope) {
scope.inTransaction(
(session) -> {
session.createQuery(
session.createStatement(
"insert into C (id) " +
"select a.id from A a " +
"where exists (" +

View File

@ -24,7 +24,7 @@ import static org.hamcrest.Matchers.is;
/**
* @author Steve Ebersole
*/
@SuppressWarnings("WeakerAccess")
@SuppressWarnings({"deprecation","WeakerAccess"})
@ServiceRegistry
@DomainModel( standardModels = StandardDomainModel.GAMBIT )
@SessionFactory

View File

@ -69,11 +69,10 @@ public class NamedHqlQueriesTest {
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery( "from VideoGame vg" )
session -> session.createQuery( "from VideoGame vg", VideoGame.class )
.list()
.forEach( vg -> session.delete( vg ) );
} );
.forEach(session::delete)
);
}
@Entity(name = "VideoGame")

View File

@ -17,9 +17,7 @@ import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.query.hql.HqlTranslator;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.orm.test.hql.Address;
@ -215,38 +213,44 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo1 Zoo 1313 Mockingbird Lane, Anywhere, IL USA
checkTestOrderByResults(
s.createQuery(
"select name, address from Zoo order by name, address"
"select name, address from Zoo order by name, address",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address from Zoo z order by z.name, z.address"
"select z.name, z.address from Zoo z order by z.name, z.address",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z2.name, z2.address from Zoo z2 where z2.name in ( select name from Zoo ) order by z2.name, z2.address"
"select z2.name, z2.address from Zoo z2 where z2.name in ( select name from Zoo ) order by z2.name, z2.address",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
// using ASC
checkTestOrderByResults(
s.createQuery(
"select name, address from Zoo order by name ASC, address ASC"
"select name, address from Zoo order by name ASC, address ASC",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address from Zoo z order by z.name ASC, z.address ASC"
"select z.name, z.address from Zoo z order by z.name ASC, z.address ASC",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z2.name, z2.address from Zoo z2 where z2.name in ( select name from Zoo ) order by z2.name ASC, z2.address ASC"
"select z2.name, z2.address from Zoo z2 where z2.name in ( select name from Zoo ) order by z2.name ASC, z2.address ASC",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
@ -277,7 +281,8 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
" z.address.city," +
" z.address.postalCode, " +
" z.address.country," +
" z.name"
" z.name",
Object[].class
).list(),
zoo3, zoo4, zoo2, zoo1, null
);
@ -290,7 +295,8 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo4 Duh Zoo 1312 Mockingbird Lane, Nowhere, IL USA
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address from Zoo z order by z.address, z.name"
"select z.name, z.address from Zoo z order by z.address, z.name",
Object[].class
).list(),
zoo3, zoo2, zoo1, zoo4, null
);
@ -298,14 +304,16 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// NOTE (6.0) - continued 3 : and the functionally equiv "full ordering"
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address from Zoo z order by z.address.city, z.address.country, z.address.stateProvince, z.address.street, z.name"
"select z.name, z.address from Zoo z order by z.address.city, z.address.country, z.address.stateProvince, z.address.street, z.name",
Object[].class
).list(),
zoo3, zoo2, zoo1, zoo4, null
);
checkTestOrderByResults(
s.createQuery(
"select name, address from Zoo order by address, name"
"select name, address from Zoo order by address, name",
Object[].class
).list(),
zoo3, zoo2, zoo1, zoo4, null
);
@ -327,13 +335,15 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// is the order used by 5.x
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address from Zoo z order by z.address.street, z.address.city"
"select z.name, z.address from Zoo z order by z.address.street, z.address.city",
Object[].class
).list(),
zoo3, zoo4, null, null, zoosWithSameAddress
);
checkTestOrderByResults(
s.createQuery(
"select name, address from Zoo order by address.street, address.city"
"select name, address from Zoo order by address.street, address.city",
Object[].class
).list(),
zoo3, zoo4, null, null, zoosWithSameAddress
);
@ -346,13 +356,15 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo3 Zoo 1312 Mockingbird Lane, Anywhere, IL USA
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address from Zoo z order by z.name"
"select z.name, z.address from Zoo z order by z.name",
Object[].class
).list(),
zoo2, zoo4, null, null, zoosWithSameName
);
checkTestOrderByResults(
s.createQuery(
"select name, address from Zoo order by name"
"select name, address from Zoo order by name",
Object[].class
).list(),
zoo2, zoo4, null, null, zoosWithSameName
);
@ -376,13 +388,15 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo3 Zoo 1312 Mockingbird Lane, Anywhere, IL USA
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address from Zoo z order by z.address DESC, z.name DESC"
"select z.name, z.address from Zoo z order by z.address DESC, z.name DESC",
Object[].class
).list(),
zoo4, zoo1, zoo2, zoo3, null
);
checkTestOrderByResults(
s.createQuery(
"select name, address from Zoo order by address DESC, name DESC"
"select name, address from Zoo order by address DESC, name DESC",
Object[].class
).list(),
zoo4, zoo1, zoo2, zoo3, null
);
@ -405,62 +419,72 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo1 Zoo 1313 Mockingbird Lane, Anywhere, IL USA
checkTestOrderByResults(
s.createQuery(
"select z2.name as zname, z2.address as zooAddress from Zoo z2 where z2.name in ( select name from Zoo ) order by zname, zooAddress"
"select z2.name as zname, z2.address as zooAddress from Zoo z2 where z2.name in ( select name from Zoo ) order by zname, zooAddress",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name as name, z.address as address from Zoo z order by name, address"
"select z.name as name, z.address as address from Zoo z order by name, address",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name as zooName, z.address as zooAddress from Zoo z order by zooName, zooAddress"
"select z.name as zooName, z.address as zooAddress from Zoo z order by zooName, zooAddress",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address as name from Zoo z order by z.name, name"
"select z.name, z.address as name from Zoo z order by z.name, name",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address as name from Zoo z order by z.name, name"
"select z.name, z.address as name from Zoo z order by z.name, name",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
// using ASC
checkTestOrderByResults(
s.createQuery(
"select z2.name as zname, z2.address as zooAddress from Zoo z2 where z2.name in ( select name from Zoo ) order by zname ASC, zooAddress ASC"
"select z2.name as zname, z2.address as zooAddress from Zoo z2 where z2.name in ( select name from Zoo ) order by zname ASC, zooAddress ASC",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name as name, z.address as address from Zoo z order by name ASC, address ASC"
"select z.name as name, z.address as address from Zoo z order by name ASC, address ASC",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name as zooName, z.address as zooAddress from Zoo z order by zooName ASC, zooAddress ASC"
"select z.name as zooName, z.address as zooAddress from Zoo z order by zooName ASC, zooAddress ASC",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address as name from Zoo z order by z.name ASC, name ASC"
"select z.name, z.address as name from Zoo z order by z.name ASC, name ASC",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address as name from Zoo z order by z.name ASC, name ASC"
"select z.name, z.address as name from Zoo z order by z.name ASC, name ASC",
Object[].class
).list(),
zoo2, zoo4, zoo3, zoo1, null
);
@ -479,26 +503,30 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo4 Duh Zoo 1312 Mockingbird Lane, Nowhere, IL USA
checkTestOrderByResults(
s.createQuery(
"select z.name as address, z.address as name from Zoo z order by name, address"
"select z.name as address, z.address as name from Zoo z order by name, address",
Object[].class
).list(),
zoo3, zoo2, zoo1, zoo4, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address as name from Zoo z order by name, z.name"
"select z.name, z.address as name from Zoo z order by name, z.name",
Object[].class
).list(),
zoo3, zoo2, zoo1, zoo4, null
);
// using ASC
checkTestOrderByResults(
s.createQuery(
"select z.name as address, z.address as name from Zoo z order by name ASC, address ASC"
"select z.name as address, z.address as name from Zoo z order by name ASC, address ASC",
Object[].class
).list(),
zoo3, zoo2, zoo1, zoo4, null
);
checkTestOrderByResults(
s.createQuery(
"select z.name, z.address as name from Zoo z order by name ASC, z.name ASC"
"select z.name, z.address as name from Zoo z order by name ASC, z.name ASC",
Object[].class
).list(),
zoo3, zoo2, zoo1, zoo4, null
);
@ -534,14 +562,16 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo3 Zoo 1312 Mockingbird Lane, Anywhere, IL USA
checkTestOrderByResults(
s.createQuery(
"select z.name as zooName, z.address as zooAddress from Zoo z order by zooName"
"select z.name as zooName, z.address as zooAddress from Zoo z order by zooName",
Object[].class
).list(),
zoo2, zoo4, null, null, zoosWithSameName
);
checkTestOrderByResults(
s.createQuery(
"select z.name as address, z.address as name from Zoo z order by address"
"select z.name as address, z.address as name from Zoo z order by address",
Object[].class
).list(),
zoo2, zoo4, null, null, zoosWithSameName
);
@ -566,7 +596,8 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// using DESC
checkTestOrderByResults(
s.createQuery(
"select z.name as zooName, z.address as zooAddress from Zoo z order by zooAddress DESC, zooName DESC"
"select z.name as zooName, z.address as zooAddress from Zoo z order by zooAddress DESC, zooName DESC",
Object[].class
).list(),
zoo4, zoo1, zoo2, zoo3, null
);
@ -590,7 +621,7 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo2 A Zoo 1313 Mockingbird Lane, Anywhere, IL USA
// zoo1 Zoo 1313 Mockingbird Lane, Anywhere, IL USA
// using DESC
List list = s.createQuery( "from Zoo z join fetch z.mammals" ).list();
List<Zoo> list = s.createQuery( "from Zoo z join fetch z.mammals", Zoo.class ).list();
t.commit();
s.close();
@ -610,9 +641,10 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo4 Duh Zoo 1312 Mockingbird Lane, Nowhere, IL USA
// zoo3 Zoo 1312 Mockingbird Lane, Anywhere, IL USA
// zoo1 Zoo 1313 Mockingbird Lane, Anywhere, IL USA
List list =
List<Zoo> list =
s.createQuery(
"select new Zoo( z.name as zname, z.address as zaddress) from Zoo z order by zname, zaddress"
"select new Zoo( z.name as zname, z.address as zaddress) from Zoo z order by zname, zaddress",
Zoo.class
).list();
assertEquals( 4, list.size() );
assertEquals( zoo2, list.get( 0 ) );
@ -627,7 +659,8 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo4 Duh Zoo 1312 Mockingbird Lane, Nowhere, IL USA
list =
s.createQuery(
"select new Zoo( z.name as zname, z.address as zaddress) from Zoo z order by zaddress, zname"
"select new Zoo( z.name as zname, z.address as zaddress) from Zoo z order by zaddress, zname",
Zoo.class
).list();
assertEquals( 4, list.size() );
assertEquals( zoo3, list.get( 0 ) );
@ -654,19 +687,20 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo4 Duh Zoo 1312 Mockingbird Lane, Nowhere, IL USA
// zoo3 Zoo 1312 Mockingbird Lane, Anywhere, IL USA
// zoo1 Zoo 1313 Mockingbird Lane, Anywhere, IL USA
List list =
List<Map> list =
s.createQuery(
"select new map( z.name as zname, z.address as zaddress ) from Zoo z left join z.mammals m order by zname, zaddress"
"select new map( z.name as zname, z.address as zaddress ) from Zoo z left join z.mammals m order by zname, zaddress",
Map.class
).list();
assertEquals( 4, list.size() );
assertEquals( zoo2.getName(), ( ( Map ) list.get( 0 ) ).get( "zname" ) );
assertEquals( zoo2.getAddress(), ( ( Map ) list.get( 0 ) ).get( "zaddress" ) );
assertEquals( zoo4.getName(), ( ( Map ) list.get( 1 ) ).get( "zname" ) );
assertEquals( zoo4.getAddress(), ( ( Map ) list.get( 1 ) ).get( "zaddress" ) );
assertEquals( zoo3.getName(), ( ( Map ) list.get( 2 ) ).get( "zname" ) );
assertEquals( zoo3.getAddress(), ( ( Map ) list.get( 2 ) ).get( "zaddress" ) );
assertEquals( zoo1.getName(), ( ( Map ) list.get( 3 ) ).get( "zname" ) );
assertEquals( zoo1.getAddress(), ( ( Map ) list.get( 3 ) ).get( "zaddress" ) );
assertEquals( zoo2.getName(), list.get( 0 ).get( "zname" ) );
assertEquals( zoo2.getAddress(), list.get( 0 ).get( "zaddress" ) );
assertEquals( zoo4.getName(), list.get( 1 ).get( "zname" ) );
assertEquals( zoo4.getAddress(), list.get( 1 ).get( "zaddress" ) );
assertEquals( zoo3.getName(), list.get( 2 ).get( "zname" ) );
assertEquals( zoo3.getAddress(), list.get( 2 ).get( "zaddress" ) );
assertEquals( zoo1.getName(), list.get( 3 ).get( "zname" ) );
assertEquals( zoo1.getAddress(), list.get( 3 ).get( "zaddress" ) );
// ordered by address, name:
// zoo3 Zoo 1312 Mockingbird Lane, Anywhere, IL USA
@ -675,21 +709,22 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo4 Duh Zoo 1312 Mockingbird Lane, Nowhere, IL USA
list =
s.createQuery(
"select new map( z.name as zname, z.address as zaddress ) from Zoo z left join z.mammals m order by zaddress, zname"
"select new map( z.name as zname, z.address as zaddress ) from Zoo z left join z.mammals m order by zaddress, zname",
Map.class
).list();
assertEquals( 4, list.size() );
assertEquals( zoo3.getName(), ( ( Map ) list.get( 0 ) ).get( "zname" ) );
assertEquals( zoo3.getAddress(), ( ( Map ) list.get( 0 ) ).get( "zaddress" ) );
assertEquals( zoo3.getName(), list.get( 0 ).get( "zname" ) );
assertEquals( zoo3.getAddress(), list.get( 0 ).get( "zaddress" ) );
assertEquals( zoo2.getName(), ( ( Map ) list.get( 1 ) ).get( "zname" ) );
assertEquals( zoo2.getAddress(), ( ( Map ) list.get( 1 ) ).get( "zaddress" ) );
assertEquals( zoo2.getName(), list.get( 1 ).get( "zname" ) );
assertEquals( zoo2.getAddress(), list.get( 1 ).get( "zaddress" ) );
assertEquals( zoo1.getName(), ( ( Map ) list.get( 2 ) ).get( "zname" ) );
assertEquals( zoo1.getAddress(), ( ( Map ) list.get( 2 ) ).get( "zaddress" ) );
assertEquals( zoo1.getName(), list.get( 2 ).get( "zname" ) );
assertEquals( zoo1.getAddress(), list.get( 2 ).get( "zaddress" ) );
assertEquals( zoo4.getName(), ( ( Map ) list.get( 3 ) ).get( "zname" ) );
assertEquals( zoo4.getAddress(), ( ( Map ) list.get( 3 ) ).get( "zaddress" ) );
assertEquals( zoo4.getName(), list.get( 3 ).get( "zname" ) );
assertEquals( zoo4.getAddress(), list.get( 3 ).get( "zaddress" ) );
t.commit();
s.close();
@ -708,17 +743,18 @@ public class OrderByTests extends BaseCoreFunctionalTestCase {
// zoo4 Duh Zoo 1312 Mockingbird Lane, Nowhere, IL USA
// zoo3 Zoo 1312 Mockingbird Lane, Anywhere, IL USA
// zoo1 Zoo 1313 Mockingbird Lane, Anywhere, IL USA
List list =
List<Object[]> list =
s.createQuery(
"select z.name as zname, count(*) as cnt from Zoo z group by z.name order by cnt desc, zname"
"select z.name as zname, count(*) as cnt from Zoo z group by z.name order by cnt desc, zname",
Object[].class
).list();
assertEquals( 3, list.size() );
assertEquals( zoo3.getName(), ( ( Object[] ) list.get( 0 ) )[ 0 ] );
assertEquals( Long.valueOf( 2 ), ( ( Object[] ) list.get( 0 ) )[ 1 ] );
assertEquals( zoo2.getName(), ( ( Object[] ) list.get( 1 ) )[ 0 ] );
assertEquals( Long.valueOf( 1 ), ( ( Object[] ) list.get( 1 ) )[ 1 ] );
assertEquals( zoo4.getName(), ( ( Object[] ) list.get( 2 ) )[ 0 ] );
assertEquals( Long.valueOf( 1 ), ( ( Object[] ) list.get( 2 ) )[ 1 ] );
assertEquals( zoo3.getName(), list.get( 0 )[ 0 ] );
assertEquals(2L, list.get( 0 )[ 1 ] );
assertEquals( zoo2.getName(), list.get( 1 )[ 0 ] );
assertEquals(1L, list.get( 1 )[ 1 ] );
assertEquals( zoo4.getName(), list.get( 2 )[ 0 ] );
assertEquals(1L, list.get( 2 )[ 1 ] );
t.commit();
s.close();
cleanupData();

View File

@ -7,7 +7,6 @@
package org.hibernate.orm.test.query.hql;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.util.ArrayList;
@ -59,7 +58,7 @@ public class ScrollableTest extends BaseCoreFunctionalTestCase {
try (Session session = openSession()) {
session.getTransaction().begin();
try {
session.createQuery( "delete from MyEntity" ).executeUpdate();
session.createStatement( "delete from MyEntity" ).executeUpdate();
session.getTransaction().commit();
}
catch (Exception e) {
@ -74,22 +73,22 @@ public class ScrollableTest extends BaseCoreFunctionalTestCase {
@Test
@TestForIssue(jiraKey = "HHH-10860")
public void testScrollableResults() {
final List params = new ArrayList();
final List<Long> params = new ArrayList<>();
params.add( 1L );
params.add( 2L );
try (Session s = openSession()) {
final Query query = s.createQuery( "from MyEntity e where e.id in (:ids)" )
final Query<MyEntity> query = s.createQuery( "from MyEntity e where e.id in (:ids)", MyEntity.class )
.setParameter( "ids", params )
.setFetchSize( 10 );
try (ScrollableResults scroll = query.scroll( ScrollMode.FORWARD_ONLY )) {
try (ScrollableResults<MyEntity> scroll = query.scroll( ScrollMode.FORWARD_ONLY )) {
int i = 0;
while ( scroll.next() ) {
if ( i == 0 ) {
assertThat( ((MyEntity) scroll.get()).getDescription(), is( "entity_1" ) );
assertThat( scroll.get().getDescription(), is( "entity_1" ) );
}
else {
assertThat( ((MyEntity) scroll.get()).getDescription(), is( "entity_2" ) );
assertThat( scroll.get().getDescription(), is( "entity_2" ) );
}
i++;
}
@ -100,22 +99,22 @@ public class ScrollableTest extends BaseCoreFunctionalTestCase {
@Test
@TestForIssue(jiraKey = "HHH-10860")
public void testScrollableResults2() {
final List params = new ArrayList();
final List<Long> params = new ArrayList<>();
params.add( 1L );
params.add( 2L );
try (Session s = openSession()) {
final Query query = s.createQuery( "from MyEntity e where e.id in (:ids)" )
final Query<MyEntity> query = s.createQuery( "from MyEntity e where e.id in (:ids)", MyEntity.class )
.setParameter( "ids", params )
.setFetchSize( 10 );
try (ScrollableResults scroll = query.scroll( )) {
try (ScrollableResults<MyEntity> scroll = query.scroll( )) {
int i = 0;
while ( scroll.next() ) {
if ( i == 0 ) {
assertThat( ((MyEntity) scroll.get()).getDescription(), is( "entity_1" ) );
assertThat( scroll.get().getDescription(), is( "entity_1" ) );
}
else {
assertThat( ((MyEntity) scroll.get()).getDescription(), is( "entity_2" ) );
assertThat( scroll.get().getDescription(), is( "entity_2" ) );
}
i++;
}

View File

@ -33,7 +33,7 @@ public class SizeAttributeReferenceTest extends BaseNonConfigCoreFunctionalTestC
public void controlGroup() {
Session session = openSession();
session.getTransaction().begin();
session.createQuery( "from EntityWithAttributeNamedSize e join e.children c where size(c) > 1" ).list();
session.createQuery( "from EntityWithAttributeNamedSize e join e.children c where size(c) > 1", EntityWithAttributeNamedSize.class ).list();
session.getTransaction().commit();
session.close();
}
@ -42,13 +42,13 @@ public class SizeAttributeReferenceTest extends BaseNonConfigCoreFunctionalTestC
public void testSizeAttributeReference() {
Session session = openSession();
session.getTransaction().begin();
session.createQuery( "from EntityWithAttributeNamedSize e join e.children c where c.size = 'abc'" ).list();
session.createQuery( "from EntityWithAttributeNamedSize e join e.children c where c.size = 'abc'", EntityWithAttributeNamedSize.class ).list();
session.getTransaction().commit();
session.close();
}
@Override
protected Class[] getAnnotatedClasses() {
protected Class<?>[] getAnnotatedClasses() {
return new Class[] { EntityWithAttributeNamedSize.class };
}

View File

@ -30,7 +30,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
/**
* @author Steve Ebersole
*/
@SuppressWarnings("WeakerAccess")
@SuppressWarnings({"deprecation", "WeakerAccess"})
@ServiceRegistry
@DomainModel( standardModels = StandardDomainModel.GAMBIT )
@SessionFactory

View File

@ -34,8 +34,8 @@ public class SubqueryOperatorsTest {
public void testEvery(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
List results = session.createQuery(
"from SimpleEntity o where o.someString >= every (select someString from SimpleEntity)" )
List<SimpleEntity> results = session.createQuery(
"from SimpleEntity o where o.someString >= every (select someString from SimpleEntity)", SimpleEntity.class )
.list();
assertThat( results.size(), is( 1 ) );
}
@ -46,15 +46,15 @@ public class SubqueryOperatorsTest {
public void testAny(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
List results = session.createQuery(
"from SimpleEntity o where o.someString >= any (select someString from SimpleEntity)" )
List<SimpleEntity> results = session.createQuery(
"from SimpleEntity o where o.someString >= any (select someString from SimpleEntity)", SimpleEntity.class )
.list();
assertThat( results.size(), is( 2 ) );
}
);
}
@Test
@Test @SuppressWarnings("deprecation")
@SkipForDialect(dialectClass = SybaseASEDialect.class, reason = "Sybase ASE does not allow a subquery in the order by clause, but we could move it to the select clause and refer to it by position", matchSubTypes = true)
public void testSubqueryInVariousClauses(SessionFactoryScope scope) {
scope.inTransaction(
@ -87,12 +87,12 @@ public class SubqueryOperatorsTest {
public void testExists(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
List results = session.createQuery(
"from SimpleEntity o where exists (select someString from SimpleEntity where someString>o.someString)" )
List<SimpleEntity> results = session.createQuery(
"from SimpleEntity o where exists (select someString from SimpleEntity where someString>o.someString)", SimpleEntity.class )
.list();
assertThat( results.size(), is( 1 ) );
results = session.createQuery(
"from SimpleEntity o where not exists (select someString from SimpleEntity where someString>o.someString)" )
"from SimpleEntity o where not exists (select someString from SimpleEntity where someString>o.someString)", SimpleEntity.class )
.list();
assertThat( results.size(), is( 1 ) );
}

View File

@ -32,11 +32,11 @@ public class TupleTest {
public void testSelectTuple(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
List results = session.createQuery(
"select o.id, (o.someString, o.someInteger), o.someLong from SimpleEntity o" )
List<Object[]> results = session.createQuery(
"select o.id, (o.someString, o.someInteger), o.someLong from SimpleEntity o", Object[].class )
.list();
assertThat( results.size(), is( 1 ) );
Object[] result = (Object[]) results.get( 0 );
Object[] result = results.get( 0 );
assertThat( result[0], is( 1 ) );
assertThat( result[1], instanceOf( Object[].class ) );
Object[] tuple = (Object[]) result[1];
@ -67,9 +67,7 @@ public class TupleTest {
@AfterEach
public void tearDown(SessionFactoryScope scope) {
scope.inTransaction(
session -> {
session.createQuery( "delete SimpleEntity" ).executeUpdate();
}
session -> session.createStatement( "delete SimpleEntity" ).executeUpdate()
);
}
}