diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/DerbyDialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/dialect/DerbyDialectTestCase.java index 44e35a5a3c..383adfb48b 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/DerbyDialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/DerbyDialectTestCase.java @@ -11,8 +11,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -import org.hibernate.hql.spi.id.MultiTableBulkIdStrategy; -import org.hibernate.hql.spi.id.local.LocalTemporaryTableBulkIdStrategy; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.junit.Test; diff --git a/hibernate-core/src/test/java/org/hibernate/dialect/Oracle8iDialectTestCase.java b/hibernate-core/src/test/java/org/hibernate/dialect/Oracle8iDialectTestCase.java index 9d643a3033..5acd0cec75 100644 --- a/hibernate-core/src/test/java/org/hibernate/dialect/Oracle8iDialectTestCase.java +++ b/hibernate-core/src/test/java/org/hibernate/dialect/Oracle8iDialectTestCase.java @@ -6,8 +6,6 @@ */ package org.hibernate.dialect; -import org.hibernate.hql.spi.id.AbstractMultiTableBulkIdStrategyImpl; - import org.junit.Test; import org.hibernate.testing.TestForIssue; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/CriteriaLiteralsTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/CriteriaLiteralsTest.java index b38f9ab95e..82b106ce63 100644 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/CriteriaLiteralsTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/nulliteral/CriteriaLiteralsTest.java @@ -25,7 +25,6 @@ import org.hibernate.dialect.H2Dialect; import org.hibernate.exception.SQLGrammarException; -import org.hibernate.hql.internal.ast.QuerySyntaxException; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; import org.hibernate.testing.RequiresDialect; diff --git a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/paths/SingularAttributeJoinTest.java b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/paths/SingularAttributeJoinTest.java index 800f7dd412..e63f4e607f 100755 --- a/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/paths/SingularAttributeJoinTest.java +++ b/hibernate-core/src/test/java/org/hibernate/jpa/test/criteria/paths/SingularAttributeJoinTest.java @@ -22,9 +22,6 @@ import org.hibernate.cfg.AvailableSettings; import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase; -import org.hibernate.query.criteria.internal.CriteriaBuilderImpl; -import org.hibernate.query.criteria.internal.PathSource; -import org.hibernate.query.criteria.internal.path.SingularAttributeJoin; import org.junit.Test; diff --git a/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java b/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java index 6ca186643f..ae634bb336 100644 --- a/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java +++ b/hibernate-core/src/test/java/org/hibernate/sql/TemplateTest.java @@ -21,9 +21,6 @@ import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.persister.entity.PropertyMapping; import org.hibernate.service.ServiceRegistry; -import org.hibernate.sql.ordering.antlr.ColumnMapper; -import org.hibernate.sql.ordering.antlr.ColumnReference; -import org.hibernate.sql.ordering.antlr.SqlValueReference; import org.hibernate.testing.ServiceRegistryBuilder; import org.hibernate.testing.junit4.BaseUnitTestCase; import org.hibernate.type.Type; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java index 65e27bdc5b..618e28e710 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/join/JoinTest.java @@ -7,6 +7,10 @@ package org.hibernate.test.annotations.join; import javax.persistence.PersistenceException; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.Root; import java.util.ArrayList; import java.util.Date; import java.util.Locale; @@ -16,7 +20,6 @@ import org.hibernate.Transaction; import org.hibernate.boot.MetadataBuilder; import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl; -import org.hibernate.criterion.Restrictions; import org.hibernate.exception.ConstraintViolationException; import org.hibernate.mapping.Join; @@ -34,7 +37,7 @@ */ public class JoinTest extends BaseNonConfigCoreFunctionalTestCase { @Test - public void testDefaultValue() throws Exception { + public void testDefaultValue() { Join join = (Join) metadata().getEntityBinding( Life.class.getName() ).getJoinClosureIterator().next(); assertEquals( "ExtendedLife", join.getTable().getName() ); org.hibernate.mapping.Column owner = new org.hibernate.mapping.Column(); @@ -125,9 +128,17 @@ public void testManyToOne() throws Exception { s = openSession(); tx = s.beginTransaction(); - Criteria crit = s.createCriteria( Life.class ); - crit.createCriteria( "owner" ).add( Restrictions.eq( "name", "kitty" ) ); - life = (Life) crit.uniqueResult(); + + CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); + CriteriaQuery criteria = criteriaBuilder.createQuery( Life.class ); + Root root = criteria.from( Life.class ); + javax.persistence.criteria.Join owner = root.join( "owner", JoinType.INNER ); + criteria.where( criteriaBuilder.equal( owner.get( "name" ), "kitty" ) ); + life = s.createQuery( criteria ).uniqueResult(); + +// Criteria crit = s.createCriteria( Life.class ); +// crit.createCriteria( "owner" ).add( Restrictions.eq( "name", "kitty" ) ); +// life = (Life) crit.uniqueResult(); assertEquals( "Long long description", life.fullDescription ); s.delete( life.owner ); s.delete( life ); @@ -136,7 +147,7 @@ public void testManyToOne() throws Exception { } @Test - public void testReferenceColumnWithBacktics() throws Exception { + public void testReferenceColumnWithBacktics() { Session s=openSession(); s.beginTransaction(); SysGroupsOrm g=new SysGroupsOrm(); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java index d3b07e876d..590f9d0f29 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/manytomany/ManyToManyTest.java @@ -14,11 +14,16 @@ import java.util.List; import java.util.Set; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Join; +import javax.persistence.criteria.JoinType; +import javax.persistence.criteria.Root; + import org.hibernate.Hibernate; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; -import org.hibernate.criterion.Restrictions; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; @@ -44,7 +49,7 @@ protected void configure(Configuration configuration) { } @Test - public void testDefault() throws Exception { + public void testDefault() { Session s; Transaction tx; s = openSession(); @@ -53,11 +58,11 @@ public void testDefault() throws Exception { fnac.setName( "Fnac" ); KnownClient emmanuel = new KnownClient(); emmanuel.setName( "Emmanuel" ); - emmanuel.setStores( new HashSet() ); - fnac.setCustomers( new HashSet() ); + emmanuel.setStores( new HashSet<>() ); + fnac.setCustomers( new HashSet<>() ); fnac.getCustomers().add( emmanuel ); emmanuel.getStores().add( fnac ); - fnac.setImplantedIn( new HashSet() ); + fnac.setImplantedIn( new HashSet<>() ); City paris = new City(); fnac.getImplantedIn().add( paris ); paris.setName( "Paris" ); @@ -70,7 +75,7 @@ public void testDefault() throws Exception { Store store; KnownClient knownClient; City city; - store = (Store) s.get( Store.class, fnac.getId() ); + store = s.get( Store.class, fnac.getId() ); assertNotNull( store ); assertNotNull( store.getCustomers() ); assertEquals( 1, store.getCustomers().size() ); @@ -85,7 +90,7 @@ public void testDefault() throws Exception { s = openSession(); tx = s.beginTransaction(); - knownClient = (KnownClient) s.get( KnownClient.class, emmanuel.getId() ); + knownClient = s.get( KnownClient.class, emmanuel.getId() ); assertNotNull( knownClient ); assertNotNull( knownClient.getStores() ); assertEquals( 1, knownClient.getStores().size() ); @@ -96,34 +101,35 @@ public void testDefault() throws Exception { } @Test - public void testCanUseCriteriaQuery() throws Exception { - Session s; - Transaction tx; - s = openSession(); - tx = s.beginTransaction(); - Store fnac = new Store(); - fnac.setName( "Fnac" ); - Supplier emi = new Supplier(); - emi.setName( "Emmanuel" ); - emi.setSuppStores( new HashSet() ); - fnac.setSuppliers( new HashSet() ); - fnac.getSuppliers().add( emi ); - emi.getSuppStores().add( fnac ); - s.persist( fnac ); - tx.commit(); - s.close(); + public void testCanUseCriteriaQuery() { + inTransaction( s -> { + Store fnac = new Store(); + fnac.setName( "Fnac" ); + Supplier emi = new Supplier(); + emi.setName( "Emmanuel" ); + emi.setSuppStores( new HashSet<>() ); + fnac.setSuppliers( new HashSet<>() ); + fnac.getSuppliers().add( emi ); + emi.getSuppStores().add( fnac ); + s.persist( fnac ); + } ); - s = openSession(); - tx = s.beginTransaction(); - List result = s.createCriteria( Supplier.class ).createAlias( "suppStores", "s" ).add( - Restrictions.eq( "s.name", "Fnac" ) ).list(); - assertEquals( 1, result.size() ); - tx.commit(); - s.close(); + inTransaction( s -> { + CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); + CriteriaQuery criteria = criteriaBuilder.createQuery( Supplier.class ); + Root root = criteria.from( Supplier.class ); + Join suppStores = root.join( "suppStores", JoinType.INNER ); + criteria.where( criteriaBuilder.equal( suppStores.get( "name" ), "Fnac" ) ); + List result = s.createQuery( criteria ).list(); + +// List result = s.createCriteria( Supplier.class ).createAlias( "suppStores", "s" ).add( +// Restrictions.eq( "s.name", "Fnac" ) ).list(); + assertEquals( 1, result.size() ); + } ); } @Test - public void testDefaultCompositePk() throws Exception { + public void testDefaultCompositePk() { Session s; Transaction tx; @@ -140,7 +146,7 @@ public void testDefaultCompositePk() throws Exception { womanPk.setFirstName( "Emma" ); womanPk.setLastName( "Peel" ); woman.setId( womanPk ); - woman.setCats( new HashSet() ); + woman.setCats( new HashSet<>() ); woman.getCats().add( cat ); cat.setHumanContacts( new HashSet() ); cat.getHumanContacts().add( woman ); @@ -151,7 +157,7 @@ public void testDefaultCompositePk() throws Exception { s = openSession(); tx = s.beginTransaction(); - Cat sameCat = (Cat) s.get( Cat.class, cat.getId() ); + Cat sameCat = s.get( Cat.class, cat.getId() ); assertNotNull( sameCat ); assertNotNull( sameCat.getHumanContacts() ); assertEquals( 1, sameCat.getHumanContacts().size() ); @@ -162,7 +168,7 @@ public void testDefaultCompositePk() throws Exception { s = openSession(); tx = s.beginTransaction(); - sameWoman = (Woman) s.get( Woman.class, woman.getId() ); + sameWoman = s.get( Woman.class, woman.getId() ); assertNotNull( sameWoman ); assertNotNull( sameWoman.getCats() ); assertEquals( 1, sameWoman.getCats().size() ); @@ -173,7 +179,7 @@ public void testDefaultCompositePk() throws Exception { } @Test - public void testMappedBy() throws Exception { + public void testMappedBy() { Session s; Transaction tx; s = openSession(); @@ -182,8 +188,8 @@ public void testMappedBy() throws Exception { fnac.setName( "Fnac" ); Supplier emi = new Supplier(); emi.setName( "Emmanuel" ); - emi.setSuppStores( new HashSet() ); - fnac.setSuppliers( new HashSet() ); + emi.setSuppStores( new HashSet<>() ); + fnac.setSuppliers( new HashSet<>() ); fnac.getSuppliers().add( emi ); emi.getSuppStores().add( fnac ); s.persist( fnac ); @@ -194,7 +200,7 @@ public void testMappedBy() throws Exception { tx = s.beginTransaction(); Store store; Supplier supplier; - store = (Store) s.get( Store.class, fnac.getId() ); + store = s.get( Store.class, fnac.getId() ); assertNotNull( store ); assertNotNull( store.getSuppliers() ); assertEquals( 1, store.getSuppliers().size() ); @@ -205,7 +211,7 @@ public void testMappedBy() throws Exception { s = openSession(); tx = s.beginTransaction(); - supplier = (Supplier) s.get( Supplier.class, emi.getId() ); + supplier = s.get( Supplier.class, emi.getId() ); assertNotNull( supplier ); assertNotNull( supplier.getSuppStores() ); assertEquals( 1, supplier.getSuppStores().size() ); @@ -216,7 +222,7 @@ public void testMappedBy() throws Exception { } @Test - public void testBasic() throws Exception { + public void testBasic() { Session s; Transaction tx; s = openSession(); @@ -236,7 +242,7 @@ public void testBasic() throws Exception { s = openSession(); tx = s.beginTransaction(); - er = (Employer) s.load( Employer.class, er.getId() ); + er = s.load( Employer.class, er.getId() ); assertNotNull( er ); assertNotNull( er.getEmployees() ); assertEquals( 1, er.getEmployees().size() ); @@ -247,7 +253,7 @@ public void testBasic() throws Exception { s = openSession(); tx = s.beginTransaction(); - ee = (Employee) s.get( Employee.class, ee.getId() ); + ee = s.get( Employee.class, ee.getId() ); assertNotNull( ee ); assertFalse( "ManyToMany mappedBy lazyness", Hibernate.isInitialized( ee.getEmployers() ) ); tx.commit(); @@ -256,7 +262,7 @@ public void testBasic() throws Exception { s = openSession(); tx = s.beginTransaction(); - ee = (Employee) s.get( Employee.class, ee.getId() ); + ee = s.get( Employee.class, ee.getId() ); assertNotNull( ee ); er = ee.getEmployers().iterator().next(); assertTrue( "second join non lazy", Hibernate.isInitialized( er ) ); @@ -267,7 +273,7 @@ public void testBasic() throws Exception { } @Test - public void testOrderByEmployee() throws Exception { + public void testOrderByEmployee() { Session s; Transaction tx; s = openSession(); @@ -293,7 +299,7 @@ public void testOrderByEmployee() throws Exception { s.flush(); s.clear(); - employer = (Employer) s.get( Employer.class, employer.getId() ); + employer = s.get( Employer.class, employer.getId() ); assertNotNull( employer ); assertNotNull( employer.getEmployees() ); assertEquals( 2, employer.getEmployees().size() ); @@ -305,7 +311,7 @@ public void testOrderByEmployee() throws Exception { // HHH-4394 @Test - public void testOrderByContractor() throws Exception { + public void testOrderByContractor() { Session s; Transaction tx; s = openSession(); @@ -341,7 +347,7 @@ public void testOrderByContractor() throws Exception { s.clear(); // assertions - employer = (Employer) s.get( Employer.class, employer.getId() ); + employer = s.get( Employer.class, employer.getId() ); assertNotNull( employer ); assertNotNull( employer.getContractors() ); assertEquals( 2, employer.getContractors().size() ); @@ -352,7 +358,7 @@ public void testOrderByContractor() throws Exception { } @Test - public void testRemoveInBetween() throws Exception { + public void testRemoveInBetween() { Session s; Transaction tx; s = openSession(); @@ -375,7 +381,7 @@ public void testRemoveInBetween() throws Exception { s = openSession(); tx = s.beginTransaction(); - er = (Employer) s.load( Employer.class, er.getId() ); + er = s.load( Employer.class, er.getId() ); assertNotNull( er ); assertNotNull( er.getEmployees() ); assertEquals( 2, er.getEmployees().size() ); @@ -392,7 +398,7 @@ public void testRemoveInBetween() throws Exception { s = openSession(); tx = s.beginTransaction(); - ee = (Employee) s.get( Employee.class, ee.getId() ); + ee = s.get( Employee.class, ee.getId() ); assertNotNull( ee ); assertFalse( "ManyToMany mappedBy lazyness", Hibernate.isInitialized( ee.getEmployers() ) ); tx.commit(); @@ -401,7 +407,7 @@ public void testRemoveInBetween() throws Exception { s = openSession(); tx = s.beginTransaction(); - ee = (Employee) s.get( Employee.class, ee.getId() ); + ee = s.get( Employee.class, ee.getId() ); assertNotNull( ee ); er = ee.getEmployers().iterator().next(); assertTrue( "second join non lazy", Hibernate.isInitialized( er ) ); @@ -413,7 +419,7 @@ public void testRemoveInBetween() throws Exception { } @Test - public void testSelf() throws Exception { + public void testSelf() { Session s; Transaction tx; s = openSession(); @@ -432,7 +438,7 @@ public void testSelf() throws Exception { s = openSession(); tx = s.beginTransaction(); - f = (Friend) s.load( Friend.class, f.getId() ); + f = s.load( Friend.class, f.getId() ); assertNotNull( f ); assertNotNull( f.getFriends() ); assertEquals( 1, f.getFriends().size() ); @@ -444,7 +450,7 @@ public void testSelf() throws Exception { } @Test - public void testCompositePk() throws Exception { + public void testCompositePk() { Session s; Transaction tx; @@ -475,19 +481,19 @@ public void testCompositePk() throws Exception { Woman w2 = new Woman(); w2.setId( w2pk ); - Set womens = new HashSet(); + Set womens = new HashSet<>(); womens.add( w1 ); m1.setWomens( womens ); - Set womens2 = new HashSet(); + Set womens2 = new HashSet<>(); womens2.add( w1 ); womens2.add( w2 ); m2.setWomens( womens2 ); - Set mens = new HashSet(); + Set mens = new HashSet<>(); mens.add( m1 ); mens.add( m2 ); w1.setMens( mens ); - Set mens2 = new HashSet(); + Set mens2 = new HashSet<>(); mens2.add( m2 ); w2.setMens( mens2 ); @@ -500,10 +506,10 @@ public void testCompositePk() throws Exception { s = openSession(); tx = s.beginTransaction(); - m1 = (Man) s.load( Man.class, m1pk ); + m1 = s.load( Man.class, m1pk ); assertFalse( m1.getWomens().isEmpty() ); assertEquals( 1, m1.getWomens().size() ); - w1 = (Woman) s.load( Woman.class, w1pk ); + w1 = s.load( Woman.class, w1pk ); assertFalse( w1.getMens().isEmpty() ); assertEquals( 2, w1.getMens().size() ); @@ -512,12 +518,12 @@ public void testCompositePk() throws Exception { } @Test - public void testAssociationTableUniqueConstraints() throws Exception { + public void testAssociationTableUniqueConstraints() { Session s = openSession(); Permission readAccess = new Permission(); readAccess.setPermission( "read" ); readAccess.setExpirationDate( new Date() ); - Collection coll = new ArrayList( 2 ); + Collection coll = new ArrayList<>( 2 ); coll.add( readAccess ); coll.add( readAccess ); Group group = new Group(); @@ -539,7 +545,7 @@ public void testAssociationTableUniqueConstraints() throws Exception { } @Test - public void testAssociationTableAndOrderBy() throws Exception { + public void testAssociationTableAndOrderBy() { Session s = openSession(); s.enableFilter( "Groupfilter" ); Permission readAccess = new Permission(); @@ -548,7 +554,7 @@ public void testAssociationTableAndOrderBy() throws Exception { Permission writeAccess = new Permission(); writeAccess.setPermission( "write" ); writeAccess.setExpirationDate( new Date( new Date().getTime() - 10*60*1000 ) ); - Collection coll = new ArrayList( 2 ); + Collection coll = new ArrayList<>( 2 ); coll.add( readAccess ); coll.add( writeAccess ); Group group = new Group(); @@ -558,7 +564,7 @@ public void testAssociationTableAndOrderBy() throws Exception { s.persist( group ); s.flush(); s.clear(); - group = (Group) s.get( Group.class, group.getId() ); + group = s.get( Group.class, group.getId() ); s.createQuery( "select g from Group g join fetch g.permissions").list(); assertEquals( "write", group.getPermissions().iterator().next().getPermission() ); s.getTransaction().rollback(); @@ -566,7 +572,7 @@ public void testAssociationTableAndOrderBy() throws Exception { } @Test - public void testAssociationTableAndOrderByWithSet() throws Exception { + public void testAssociationTableAndOrderByWithSet() { Session s = openSession(); s.enableFilter( "Groupfilter" ); @@ -582,7 +588,7 @@ public void testAssociationTableAndOrderByWithSet() throws Exception { executeAccess.setPermission( "execute" ); executeAccess.setExpirationDate( new Date( new Date().getTime() - 5*60*1000 ) ); - Set coll = new HashSet( 3 ); + Set coll = new HashSet<>( 3 ); coll.add( readAccess ); coll.add( writeAccess ); coll.add( executeAccess ); @@ -595,7 +601,7 @@ public void testAssociationTableAndOrderByWithSet() throws Exception { s.flush(); s.clear(); - group = (GroupWithSet) s.get( GroupWithSet.class, group.getId() ); + group = s.get( GroupWithSet.class, group.getId() ); s.createQuery( "select g from Group g join fetch g.permissions").list(); Iterator permIter = group.getPermissions().iterator(); assertEquals( "write", permIter.next().getPermission() ); @@ -606,7 +612,7 @@ public void testAssociationTableAndOrderByWithSet() throws Exception { } @Test - public void testJoinedSubclassManyToMany() throws Exception { + public void testJoinedSubclassManyToMany() { Session s = openSession(); Zone a = new Zone(); InspectorPrefixes ip = new InspectorPrefixes( "dgi" ); @@ -618,7 +624,7 @@ public void testJoinedSubclassManyToMany() throws Exception { s.close(); s = openSession(); tx = s.beginTransaction(); - ip = (InspectorPrefixes) s.get( InspectorPrefixes.class, ip.getId() ); + ip = s.get( InspectorPrefixes.class, ip.getId() ); assertNotNull( ip ); assertEquals( 1, ip.getAreas().size() ); assertEquals( a.getId(), ip.getAreas().get( 0 ).getId() ); @@ -629,7 +635,7 @@ public void testJoinedSubclassManyToMany() throws Exception { } @Test - public void testJoinedSubclassManyToManyWithNonPkReference() throws Exception { + public void testJoinedSubclassManyToManyWithNonPkReference() { Session s = openSession(); Zone a = new Zone(); InspectorPrefixes ip = new InspectorPrefixes( "dgi" ); @@ -642,7 +648,7 @@ public void testJoinedSubclassManyToManyWithNonPkReference() throws Exception { s.close(); s = openSession(); tx = s.beginTransaction(); - ip = (InspectorPrefixes) s.get( InspectorPrefixes.class, ip.getId() ); + ip = s.get( InspectorPrefixes.class, ip.getId() ); assertNotNull( ip ); assertEquals( 1, ip.getDesertedAreas().size() ); assertEquals( a.getId(), ip.getDesertedAreas().get( 0 ).getId() ); @@ -653,7 +659,7 @@ public void testJoinedSubclassManyToManyWithNonPkReference() throws Exception { } @Test - public void testReferencedColumnNameToSuperclass() throws Exception { + public void testReferencedColumnNameToSuperclass() { Session s = openSession(); Transaction tx = s.beginTransaction(); BuildingCompany comp = new BuildingCompany(); @@ -665,7 +671,7 @@ public void testReferencedColumnNameToSuperclass() throws Exception { s.persist( building ); s.flush(); s.clear(); - building = (Building) s.get( Building.class, building.getId() ); + building = s.get( Building.class, building.getId() ); assertEquals( comp.getName(), building.getCompany().getName() ); tx.rollback(); s.close(); @@ -673,7 +679,7 @@ public void testReferencedColumnNameToSuperclass() throws Exception { @Test @TestForIssue( jiraKey = "HHH-4685" ) - public void testManyToManyEmbeddableBiDirectionalDotNotationInMappedBy() throws Exception { + public void testManyToManyEmbeddableBiDirectionalDotNotationInMappedBy() { // Section 11.1.25 // The ManyToMany annotation may be used within an embeddable class contained within an entity class to specify a // relationship to a collection of entities[101]. If the relationship is bidirectional and the entity containing @@ -687,8 +693,8 @@ public void testManyToManyEmbeddableBiDirectionalDotNotationInMappedBy() throws s.getTransaction().begin(); Employee e = new Employee(); e.setName( "Sharon" ); - List phoneNumbers = new ArrayList(); - Collection employees = new ArrayList(); + List phoneNumbers = new ArrayList<>(); + Collection employees = new ArrayList<>(); employees.add( e ); ContactInfo contactInfo = new ContactInfo(); PhoneNumber number = new PhoneNumber(); @@ -702,7 +708,7 @@ public void testManyToManyEmbeddableBiDirectionalDotNotationInMappedBy() throws s = openSession(); s.getTransaction().begin(); - e = (Employee)s.get( e.getClass(),e.getId() ); + e = s.get( e.getClass(),e.getId() ); // follow both directions of many to many association assertEquals("same employee", e.getName(), e.getContactInfo().getPhoneNumbers().get(0).getEmployees().iterator().next().getName()); s.getTransaction().commit(); @@ -712,7 +718,7 @@ public void testManyToManyEmbeddableBiDirectionalDotNotationInMappedBy() throws @Test @TestForIssue( jiraKey = "HHH-4685" ) - public void testOneToManyEmbeddableBiDirectionalDotNotationInMappedBy() throws Exception { + public void testOneToManyEmbeddableBiDirectionalDotNotationInMappedBy() { // Section 11.1.26 // The ManyToOne annotation may be used within an embeddable class to specify a relationship from the embeddable // class to an entity class. If the relationship is bidirectional, the non-owning OneToMany entity side must use the @@ -727,7 +733,7 @@ public void testOneToManyEmbeddableBiDirectionalDotNotationInMappedBy() throws E JobInfo job = new JobInfo(); job.setJobDescription( "Sushi Chef" ); ProgramManager pm = new ProgramManager(); - Collection employees = new ArrayList(); + Collection employees = new ArrayList<>(); employees.add(e); pm.setManages( employees ); job.setPm(pm); @@ -738,7 +744,7 @@ public void testOneToManyEmbeddableBiDirectionalDotNotationInMappedBy() throws E s = openSession(); s.getTransaction().begin(); - e = (Employee) s.get( e.getClass(), e.getId() ); + e = s.get( e.getClass(), e.getId() ); assertEquals( "same job in both directions", e.getJobInfo().getJobDescription(), e.getJobInfo().getPm().getManages().iterator().next().getJobInfo().getJobDescription() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java index 063969c646..642d9d0d1d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/onetoone/OneToOneTest.java @@ -8,12 +8,15 @@ import java.util.Iterator; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; + import org.hibernate.EmptyInterceptor; import org.hibernate.MappingException; import org.hibernate.query.Query; import org.hibernate.Session; import org.hibernate.Transaction; -import org.hibernate.criterion.Restrictions; import org.hibernate.mapping.Column; import org.hibernate.mapping.Join; import org.hibernate.mapping.PersistentClass; @@ -53,7 +56,7 @@ public void testEagerFetching() throws Exception { final Client client = TransactionUtil.doInHibernate( this::sessionFactory, session -> { Query q = session.createQuery( "select c from Client c where c.name = :name" ); - q.setString( "name", clientName ); + q.setParameter( "name", clientName ); Client c = (Client) q.uniqueResult(); //c = (Client) s.get(Client.class, c.getId()); @@ -350,9 +353,14 @@ public void testPkOneToOneSelectStatementDoesNotGenerateExtraJoin() { s.flush(); s.clear(); - owner = (Owner) s.createCriteria( Owner.class ) - .add( Restrictions.idEq( owner.getId() ) ) - .uniqueResult(); + CriteriaBuilder criteriaBuilder = s.getCriteriaBuilder(); + CriteriaQuery criteria = criteriaBuilder.createQuery( Owner.class ); + Root root = criteria.from( Owner.class ); + criteria.where( criteriaBuilder.equal( root.get("id"), owner.getId() ) ); + owner = s.createQuery( criteria ).uniqueResult(); +// owner = (Owner) s.createCriteria( Owner.class ) +// .add( Restrictions.idEq( owner.getId() ) ) +// .uniqueResult(); assertNotNull( owner ); assertNotNull( owner.getAddress() ); @@ -360,9 +368,14 @@ public void testPkOneToOneSelectStatementDoesNotGenerateExtraJoin() { s.flush(); s.clear(); - address = (OwnerAddress) s.createCriteria( OwnerAddress.class ) - .add( Restrictions.idEq( address.getId() ) ) - .uniqueResult(); + CriteriaQuery criteriaQuery = criteriaBuilder.createQuery( OwnerAddress.class ); + Root ownerAddressRoot = criteriaQuery.from( OwnerAddress.class ); + criteriaQuery.where( criteriaBuilder.equal( ownerAddressRoot.get( "id" ), address.getId() ) ); + + address = s.createQuery( criteriaQuery ).uniqueResult(); +// address = (OwnerAddress) s.createCriteria( OwnerAddress.class ) +// .add( Restrictions.idEq( address.getId() ) ) +// .uniqueResult(); address = s.get( OwnerAddress.class, address.getId() ); assertNotNull( address ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/exceptionhandling/ExceptionExpectations.java b/hibernate-core/src/test/java/org/hibernate/test/exceptionhandling/ExceptionExpectations.java index 7c8dbc6081..a0db91fcf1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/exceptionhandling/ExceptionExpectations.java +++ b/hibernate-core/src/test/java/org/hibernate/test/exceptionhandling/ExceptionExpectations.java @@ -16,7 +16,6 @@ import org.hibernate.TransactionException; import org.hibernate.TransientObjectException; import org.hibernate.exception.ConstraintViolationException; -import org.hibernate.hql.internal.ast.QuerySyntaxException; import org.hibernate.id.IdentifierGenerationException; import static org.hamcrest.CoreMatchers.instanceOf; diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java b/hibernate-core/src/test/java/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java index b103e21d5a..1be74a0829 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/jpa/ql/JPAQLComplianceTest.java @@ -10,8 +10,8 @@ import java.util.List; import org.hibernate.Session; -import org.hibernate.hql.internal.ast.QuerySyntaxException; import org.hibernate.query.Query; +import org.hibernate.query.SemanticException; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.transaction.TransactionUtil2; @@ -41,7 +41,7 @@ public void testAliasNameSameAsUnqualifiedEntityName() { } @Test - public void testIdentifierCaseSensitive() throws Exception { + public void testIdentifierCaseSensitive() { Session s = openSession( ); // a control test (a user reported that the JPA 'case insensitivity' support // caused problems with the "discriminator resolution" code; unable to reproduce)... @@ -54,7 +54,7 @@ public void testIdentifierCaseSensitive() throws Exception { } @Test - public void testIdentifierCasesensitivityAndDuplicateFromElements() throws Exception { + public void testIdentifierCasesensitivityAndDuplicateFromElements() { Session s = openSession(); s.createQuery( "select e from MyEntity e where exists (select 1 from MyEntity e2 where e2.other.name = 'something' and e2.other.other = e)" ); s.close(); @@ -86,7 +86,7 @@ public void testParametersMixturePositionalAndNamed() { fail( "Expecting QuerySyntaxException because of named and positional parameters mixture" ); } catch ( IllegalArgumentException e ) { assertNotNull( e.getCause() ); - assertTyping( QuerySyntaxException.class, e.getCause() ); + assertTyping( SemanticException.class, e.getCause() ); } } ); @@ -104,7 +104,7 @@ public void testParametersMixtureNamedAndPositional() { } catch (IllegalArgumentException e) { assertNotNull( e.getCause() ); - assertTyping( QuerySyntaxException.class, e.getCause() ); + assertTyping( SemanticException.class, e.getCause() ); } } ); @@ -164,7 +164,7 @@ public void testParametersMixtureNamedCollectionAndPositional() { } catch (IllegalArgumentException e) { assertNotNull( e.getCause() ); - assertTyping( QuerySyntaxException.class, e.getCause() ); + assertTyping( SemanticException.class, e.getCause() ); } } ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/OrderByAnnotationTests.java b/hibernate-core/src/test_legacy/org/hibernate/test/jpa/compliance/tck2_2/OrderByAnnotationTests.java similarity index 90% rename from hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/OrderByAnnotationTests.java rename to hibernate-core/src/test_legacy/org/hibernate/test/jpa/compliance/tck2_2/OrderByAnnotationTests.java index dec94464bb..afcf66bd92 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/jpa/compliance/tck2_2/OrderByAnnotationTests.java +++ b/hibernate-core/src/test_legacy/org/hibernate/test/jpa/compliance/tck2_2/OrderByAnnotationTests.java @@ -19,12 +19,6 @@ import org.hibernate.dialect.Dialect; import org.hibernate.dialect.function.SQLFunctionRegistry; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.sql.ordering.antlr.ColumnMapper; -import org.hibernate.sql.ordering.antlr.ColumnReference; -import org.hibernate.sql.ordering.antlr.OrderByFragmentTranslator; -import org.hibernate.sql.ordering.antlr.OrderByTranslation; -import org.hibernate.sql.ordering.antlr.SqlValueReference; -import org.hibernate.sql.ordering.antlr.TranslationContext; import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase; import org.junit.Test;