HHH-9457 : EntityGraph with order by using Oracle10gDialect

This commit is contained in:
Gail Badner 2015-02-20 17:32:06 -08:00
parent f46fe0ff25
commit 9337f73185
4 changed files with 86 additions and 1 deletions

View File

@ -48,6 +48,11 @@ public class Oracle10gDialect extends Oracle9iDialect {
return new ANSIJoinFragment();
}
@Override
public String getCrossJoinSeparator() {
return " cross join ";
}
@Override
public String getWriteLockString(int timeout) {
if ( timeout == LockOptions.SKIP_LOCKED ) {

View File

@ -51,4 +51,8 @@ public class Company {
@ElementCollection(fetch = FetchType.EAGER)
public Set<String> phoneNumbers = new HashSet<String>();
public Location getLocation() {
return location;
}
}

View File

@ -35,4 +35,8 @@ public class Location {
public String address;
public int zip;
public int getZip() {
return zip;
}
}

View File

@ -20,10 +20,13 @@
*/
package org.hibernate.jpa.test.graphs.queryhint;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityGraph;
import javax.persistence.EntityManager;
@ -94,6 +97,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
assertTrue( Hibernate.isInitialized( company.employees ) );
assertTrue( Hibernate.isInitialized( company.location ) );
assertEquals( 12345, company.location.zip );
assertTrue( Hibernate.isInitialized( company.markets ) );
// With "loadgraph", non-specified attributes use the fetch modes defined in the mappings. So, here,
// @ElementCollection(fetch = FetchType.EAGER) should cause the follow-on selects to happen.
@ -117,6 +121,74 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
assertTrue(foundManager);
}
@Test
@TestForIssue( jiraKey = "HHH-9457")
public void testLoadGraphOrderByWithImplicitJoin() {
EntityManager entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
// create a new Company at a different location in a different zip code
Location location = new Location();
location.address = "123 somewhere";
location.zip = 11234;
entityManager.persist( location );
Company companyNew = new Company();
companyNew.location = location;
entityManager.persist( companyNew );
entityManager.getTransaction().commit();
entityManager.close();
entityManager = getOrCreateEntityManager();
entityManager.getTransaction().begin();
EntityGraph<Company> entityGraph = entityManager.createEntityGraph( Company.class );
//entityGraph.addAttributeNodes( "location" );
entityGraph.addAttributeNodes( "markets" );
Query query = entityManager.createQuery( "from " + Company.class.getName() + " c order by c.location.zip, c.id" );
query.setHint( QueryHints.HINT_LOADGRAPH, entityGraph );
List results = query.getResultList();
// we expect 3 results:
// - 1st will be the Company with location.zip == 11234 with an empty markets collection
// - 2nd and 3rd should be the Company with location.zip == 12345
// (2nd and 3rd are duplicated because that entity has 2 elements in markets collection
assertEquals( 3, results.size() );
Company companyResult = (Company) results.get( 0 );
assertFalse( Hibernate.isInitialized( companyResult.employees ) );
assertFalse( Hibernate.isInitialized( companyResult.location ) );
// initialize and check zip
// TODO: must have getters to access lazy entity after being initialized (why?)
//assertEquals( 11234, companyResult.location.zip );
assertEquals( 11234, companyResult.getLocation().getZip() );
assertTrue( Hibernate.isInitialized( companyResult.markets ) );
assertEquals( 0, companyResult.markets.size() );
// With "loadgraph", non-specified attributes use the fetch modes defined in the mappings. So, here,
// @ElementCollection(fetch = FetchType.EAGER) should cause the follow-on selects to happen.
assertTrue( Hibernate.isInitialized( companyResult.phoneNumbers ) );
assertEquals( 0, companyResult.phoneNumbers.size() );
companyResult = (Company) results.get( 1 );
assertFalse( Hibernate.isInitialized( companyResult.employees ) );
assertFalse( Hibernate.isInitialized( companyResult.location ) );
// initialize and check zip
// TODO: must have getters to access lazy entity after being initialized (why?)
//assertEquals( 12345, companyResult.location.zip );
assertEquals( 12345, companyResult.getLocation().getZip() );
assertTrue( Hibernate.isInitialized( companyResult.markets ) );
assertEquals( 2, companyResult.markets.size() );
// With "loadgraph", non-specified attributes use the fetch modes defined in the mappings. So, here,
// @ElementCollection(fetch = FetchType.EAGER) should cause the follow-on selects to happen.
assertTrue( Hibernate.isInitialized( companyResult.phoneNumbers ) );
assertEquals( 2, companyResult.phoneNumbers.size() );
assertSame( companyResult, results.get( 2 ) );
entityManager.getTransaction().commit();
entityManager.close();
}
@Test
@TestForIssue( jiraKey = "HHH-9448")
@FailureExpected( jiraKey = "HHH-9448")