HHH-9457 : EntityGraph with order by using Oracle10gDialect
(cherry picked from commit 9337f73185
)
This commit is contained in:
parent
ff8c75cbea
commit
27ac1dbbe4
|
@ -48,6 +48,11 @@ public class Oracle10gDialect extends Oracle9iDialect {
|
||||||
return new ANSIJoinFragment();
|
return new ANSIJoinFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getCrossJoinSeparator() {
|
||||||
|
return " cross join ";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getWriteLockString(int timeout) {
|
public String getWriteLockString(int timeout) {
|
||||||
if ( timeout == LockOptions.SKIP_LOCKED ) {
|
if ( timeout == LockOptions.SKIP_LOCKED ) {
|
||||||
|
|
|
@ -51,4 +51,8 @@ public class Company {
|
||||||
|
|
||||||
@ElementCollection(fetch = FetchType.EAGER)
|
@ElementCollection(fetch = FetchType.EAGER)
|
||||||
public Set<String> phoneNumbers = new HashSet<String>();
|
public Set<String> phoneNumbers = new HashSet<String>();
|
||||||
|
|
||||||
|
public Location getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,4 +35,8 @@ public class Location {
|
||||||
public String address;
|
public String address;
|
||||||
|
|
||||||
public int zip;
|
public int zip;
|
||||||
|
|
||||||
|
public int getZip() {
|
||||||
|
return zip;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,13 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.jpa.test.graphs.queryhint;
|
package org.hibernate.jpa.test.graphs.queryhint;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import javax.persistence.EntityGraph;
|
import javax.persistence.EntityGraph;
|
||||||
import javax.persistence.EntityManager;
|
import javax.persistence.EntityManager;
|
||||||
|
@ -94,6 +97,7 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
|
|
||||||
assertTrue( Hibernate.isInitialized( company.employees ) );
|
assertTrue( Hibernate.isInitialized( company.employees ) );
|
||||||
assertTrue( Hibernate.isInitialized( company.location ) );
|
assertTrue( Hibernate.isInitialized( company.location ) );
|
||||||
|
assertEquals( 12345, company.location.zip );
|
||||||
assertTrue( Hibernate.isInitialized( company.markets ) );
|
assertTrue( Hibernate.isInitialized( company.markets ) );
|
||||||
// With "loadgraph", non-specified attributes use the fetch modes defined in the mappings. So, here,
|
// 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.
|
// @ElementCollection(fetch = FetchType.EAGER) should cause the follow-on selects to happen.
|
||||||
|
@ -117,6 +121,74 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
|
||||||
assertTrue(foundManager);
|
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
|
@Test
|
||||||
@TestForIssue( jiraKey = "HHH-9448")
|
@TestForIssue( jiraKey = "HHH-9448")
|
||||||
@FailureExpected( jiraKey = "HHH-9448")
|
@FailureExpected( jiraKey = "HHH-9448")
|
||||||
|
|
Loading…
Reference in New Issue