HHH-13011 : Update tests to work in 5.1 branch; make changes due to default for hibernate.use_entity_where_clause_for_collections changed to false in 5.1
This commit is contained in:
parent
2b871da951
commit
c4e9be53af
|
@ -20,6 +20,7 @@ import javax.persistence.ManyToMany;
|
|||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.annotations.Where;
|
||||
import org.hibernate.annotations.WhereJoinTable;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
@ -28,14 +29,14 @@ import org.hibernate.testing.TestForIssue;
|
|||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS = false
|
||||
* Tests association collections with default AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS
|
||||
* (which is false).
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
|
@ -46,11 +47,6 @@ public class EagerToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunc
|
|||
return new Class[] { Product.class, Category.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
settings.put( AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS, "false" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13011" )
|
||||
public void testAssociatedWhereClause() {
|
||||
|
@ -93,20 +89,21 @@ public class EagerToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunc
|
|||
product.categoriesWithDescManyToMany.add( building );
|
||||
product.categoriesWithDescIdLt4ManyToMany.add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.categoriesOneToMany.size() );
|
||||
|
@ -119,29 +116,32 @@ public class EagerToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunc
|
|||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNotNull( c );
|
||||
c.inactive = true;
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.categoriesOneToMany.size() );
|
||||
|
@ -154,8 +154,9 @@ public class EagerToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunc
|
|||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.test.where.annotations;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
|
@ -19,23 +20,23 @@ import javax.persistence.ManyToMany;
|
|||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.annotations.Where;
|
||||
import org.hibernate.annotations.WhereJoinTable;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests association collections with default AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS,
|
||||
* which is true.
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS=true.
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
|
@ -46,6 +47,11 @@ public class EagerToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
return new Class[] { Product.class, Category.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
settings.put( AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS, "true" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13011" )
|
||||
public void testAssociatedWhereClause() {
|
||||
|
@ -88,20 +94,21 @@ public class EagerToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
product.categoriesWithDescManyToMany.add( building );
|
||||
product.categoriesWithDescIdLt4ManyToMany.add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.categoriesOneToMany.size() );
|
||||
|
@ -114,29 +121,32 @@ public class EagerToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNotNull( c );
|
||||
c.inactive = true;
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 3, p.categoriesOneToMany.size() );
|
||||
|
@ -149,8 +159,9 @@ public class EagerToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 2, 4 } );
|
||||
assertEquals( 1, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
|
@ -20,6 +20,7 @@ import javax.persistence.ManyToMany;
|
|||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.annotations.Where;
|
||||
import org.hibernate.annotations.WhereJoinTable;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
@ -28,14 +29,13 @@ import org.hibernate.testing.TestForIssue;
|
|||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS = true
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS=true.
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
|
@ -93,20 +93,21 @@ public class EagerToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunction
|
|||
product.categoriesWithDescManyToMany.add( building );
|
||||
product.categoriesWithDescIdLt4ManyToMany.add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.categoriesOneToMany.size() );
|
||||
|
@ -119,29 +120,32 @@ public class EagerToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunction
|
|||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNotNull( c );
|
||||
c.inactive = true;
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 3, p.categoriesOneToMany.size() );
|
||||
|
@ -153,9 +157,10 @@ public class EagerToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunction
|
|||
assertEquals( 2, p.categoriesWithDescManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 2, 4 } );
|
||||
assertEquals( 1, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 2 } );
|
||||
}
|
||||
);
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 2 } );
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
|
@ -42,6 +42,8 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS=true.
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class LazyManyToManyNonUniqueIdWhereTest extends BaseCoreFunctionalTestCase {
|
||||
|
|
|
@ -39,6 +39,8 @@ import static org.junit.Assert.assertTrue;
|
|||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS=true.
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
public class LazyOneToManyNonUniqueIdWhereTest extends BaseCoreFunctionalTestCase {
|
||||
|
|
|
@ -20,6 +20,7 @@ import javax.persistence.ManyToMany;
|
|||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.annotations.Where;
|
||||
import org.hibernate.annotations.WhereJoinTable;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
@ -28,14 +29,14 @@ import org.hibernate.testing.TestForIssue;
|
|||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS = false
|
||||
* Tests association collections with default AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS
|
||||
* (which is false).
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
|
@ -46,11 +47,6 @@ public class LazyToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunct
|
|||
return new Class[] { Product.class, Category.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
settings.put( AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS, "false" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13011" )
|
||||
public void testAssociatedWhereClause() {
|
||||
|
@ -93,20 +89,21 @@ public class LazyToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunct
|
|||
product.categoriesWithDescManyToMany.add( building );
|
||||
product.categoriesWithDescIdLt4ManyToMany.add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.categoriesOneToMany.size() );
|
||||
|
@ -119,29 +116,32 @@ public class LazyToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunct
|
|||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNotNull( c );
|
||||
c.inactive = true;
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.categoriesOneToMany.size() );
|
||||
|
@ -153,9 +153,10 @@ public class LazyToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunct
|
|||
assertEquals( 3, p.categoriesWithDescManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 1, 2 } );
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.hibernate.test.where.annotations;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
|
@ -19,22 +20,22 @@ import javax.persistence.ManyToMany;
|
|||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.annotations.Where;
|
||||
import org.hibernate.annotations.WhereJoinTable;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests association collections with default AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS,
|
||||
* which is true.
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS=true.
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
|
@ -45,6 +46,11 @@ public class LazyToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
return new Class[] { Product.class, Category.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
settings.put( AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS, "true" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13011" )
|
||||
public void testAssociatedWhereClause() {
|
||||
|
@ -87,20 +93,21 @@ public class LazyToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
product.categoriesWithDescManyToMany.add( building );
|
||||
product.categoriesWithDescIdLt4ManyToMany.add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.categoriesOneToMany.size() );
|
||||
|
@ -113,29 +120,32 @@ public class LazyToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNotNull( c );
|
||||
c.inactive = true;
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 3, p.categoriesOneToMany.size() );
|
||||
|
@ -147,9 +157,10 @@ public class LazyToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
assertEquals( 2, p.categoriesWithDescManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 2, 4 } );
|
||||
assertEquals( 1, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 2 } );
|
||||
}
|
||||
);
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 2 } );
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
|
@ -20,6 +20,7 @@ import javax.persistence.ManyToMany;
|
|||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.annotations.Where;
|
||||
import org.hibernate.annotations.WhereJoinTable;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
@ -28,7 +29,6 @@ import org.hibernate.testing.TestForIssue;
|
|||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
@ -93,20 +93,21 @@ public class LazyToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunctiona
|
|||
product.categoriesWithDescManyToMany.add( building );
|
||||
product.categoriesWithDescIdLt4ManyToMany.add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.categoriesOneToMany.size() );
|
||||
|
@ -119,29 +120,32 @@ public class LazyToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunctiona
|
|||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNotNull( c );
|
||||
c.inactive = true;
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.id );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.id );
|
||||
assertNotNull( p );
|
||||
assertEquals( 3, p.categoriesOneToMany.size() );
|
||||
|
@ -154,8 +158,9 @@ public class LazyToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunctiona
|
|||
checkIds( p.categoriesWithDescManyToMany, new Integer[] { 2, 4 } );
|
||||
assertEquals( 1, p.categoriesWithDescIdLt4ManyToMany.size() );
|
||||
checkIds( p.categoriesWithDescIdLt4ManyToMany, new Integer[] { 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
|
@ -11,20 +11,21 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS = false
|
||||
* Tests association collections with default AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS
|
||||
* (which is false).
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
|
@ -34,11 +35,6 @@ public class EagerToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunc
|
|||
protected String[] getMappings() {
|
||||
return new String[] { "where/hbm/EagerToManyWhere.hbm.xml" };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
settings.put( AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS, "false" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13011" )
|
||||
|
@ -82,20 +78,21 @@ public class EagerToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunc
|
|||
product.getCategoriesWithDescManyToMany().add( building );
|
||||
product.getCategoriesWithDescIdLt4ManyToMany().add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.getCategoriesOneToMany().size() );
|
||||
|
@ -108,29 +105,31 @@ public class EagerToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunc
|
|||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNotNull( c );
|
||||
c.setInactive( true );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.getCategoriesOneToMany().size() );
|
||||
|
@ -143,8 +142,9 @@ public class EagerToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunc
|
|||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
|
@ -8,21 +8,23 @@ package org.hibernate.test.where.hbm;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests association collections with default AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS,
|
||||
* which is true.
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS=true.
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
|
@ -33,6 +35,11 @@ public class EagerToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
return new String[] { "where/hbm/EagerToManyWhere.hbm.xml" };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
settings.put( AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS, "true" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13011" )
|
||||
public void testAssociatedWhereClause() {
|
||||
|
@ -75,20 +82,21 @@ public class EagerToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
product.getCategoriesWithDescManyToMany().add( building );
|
||||
product.getCategoriesWithDescIdLt4ManyToMany().add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.getCategoriesOneToMany().size() );
|
||||
|
@ -101,29 +109,32 @@ public class EagerToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNotNull( c );
|
||||
c.setInactive( true );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 3, p.getCategoriesOneToMany().size() );
|
||||
|
@ -136,8 +147,9 @@ public class EagerToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 2, 4 } );
|
||||
assertEquals( 1, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
|
@ -11,13 +11,13 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
@ -82,20 +82,21 @@ public class EagerToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunction
|
|||
product.getCategoriesWithDescManyToMany().add( building );
|
||||
product.getCategoriesWithDescIdLt4ManyToMany().add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.getCategoriesOneToMany().size() );
|
||||
|
@ -108,29 +109,32 @@ public class EagerToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunction
|
|||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNotNull( c );
|
||||
c.setInactive( true );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 3, p.getCategoriesOneToMany().size() );
|
||||
|
@ -142,9 +146,10 @@ public class EagerToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunction
|
|||
assertEquals( 2, p.getCategoriesWithDescManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 2, 4 } );
|
||||
assertEquals( 1, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 2 } );
|
||||
}
|
||||
);
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 2 } );
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
|
@ -11,20 +11,21 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS = false
|
||||
* Tests association collections with default AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS
|
||||
* (which is false).
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
|
@ -82,20 +83,21 @@ public class LazyToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunct
|
|||
product.getCategoriesWithDescManyToMany().add( building );
|
||||
product.getCategoriesWithDescIdLt4ManyToMany().add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.getCategoriesOneToMany().size() );
|
||||
|
@ -108,29 +110,32 @@ public class LazyToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunct
|
|||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNotNull( c );
|
||||
c.setInactive( true );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.getCategoriesOneToMany().size() );
|
||||
|
@ -142,9 +147,10 @@ public class LazyToManyWhereDontUseClassWhereTest extends BaseNonConfigCoreFunct
|
|||
assertEquals( 3, p.getCategoriesWithDescManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 1, 2 } );
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
|
@ -8,21 +8,23 @@ package org.hibernate.test.where.hbm;
|
|||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests association collections with default AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS,
|
||||
* which is true.
|
||||
* Tests association collections with AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS=true,
|
||||
*
|
||||
* @author Gail Badner
|
||||
*/
|
||||
|
@ -33,6 +35,11 @@ public class LazyToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
return new String[] { "where/hbm/LazyToManyWhere.hbm.xml" };
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addSettings(Map settings) {
|
||||
settings.put( AvailableSettings.USE_ENTITY_WHERE_CLAUSE_FOR_COLLECTIONS, "true" );
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestForIssue( jiraKey = "HHH-13011" )
|
||||
public void testAssociatedWhereClause() {
|
||||
|
@ -75,20 +82,21 @@ public class LazyToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
product.getCategoriesWithDescManyToMany().add( building );
|
||||
product.getCategoriesWithDescIdLt4ManyToMany().add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.getCategoriesOneToMany().size() );
|
||||
|
@ -101,29 +109,32 @@ public class LazyToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNotNull( c );
|
||||
c.setInactive( true );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 3, p.getCategoriesOneToMany().size() );
|
||||
|
@ -136,8 +147,9 @@ public class LazyToManyWhereTest extends BaseNonConfigCoreFunctionalTestCase {
|
|||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 2, 4 } );
|
||||
assertEquals( 1, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
|
@ -11,13 +11,13 @@ import java.util.HashSet;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
|
||||
import org.hibernate.testing.TestForIssue;
|
||||
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
@ -82,20 +82,21 @@ public class LazyToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunctiona
|
|||
product.getCategoriesWithDescManyToMany().add( building );
|
||||
product.getCategoriesWithDescIdLt4ManyToMany().add( building );
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
Session session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
session.persist( flowers );
|
||||
session.persist( vegetables );
|
||||
session.persist( dogs );
|
||||
session.persist( building );
|
||||
session.persist( product );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 4, p.getCategoriesOneToMany().size() );
|
||||
|
@ -108,29 +109,32 @@ public class LazyToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunctiona
|
|||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 1, 2, 4 } );
|
||||
assertEquals( 2, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 1, 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNotNull( c );
|
||||
c.setInactive( true );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Category c = session.get( Category.class, flowers.getId() );
|
||||
assertNull( c );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
|
||||
doInHibernate(
|
||||
this::sessionFactory,
|
||||
session -> {
|
||||
session = openSession();
|
||||
session.beginTransaction();
|
||||
{
|
||||
Product p = session.get( Product.class, product.getId() );
|
||||
assertNotNull( p );
|
||||
assertEquals( 3, p.getCategoriesOneToMany().size() );
|
||||
|
@ -143,8 +147,9 @@ public class LazyToManyWhereUseClassWhereTest extends BaseNonConfigCoreFunctiona
|
|||
checkIds( p.getCategoriesWithDescManyToMany(), new Integer[] { 2, 4 } );
|
||||
assertEquals( 1, p.getCategoriesWithDescIdLt4ManyToMany().size() );
|
||||
checkIds( p.getCategoriesWithDescIdLt4ManyToMany(), new Integer[] { 2 } );
|
||||
}
|
||||
);
|
||||
}
|
||||
session.getTransaction().commit();
|
||||
session.close();
|
||||
}
|
||||
|
||||
private void checkIds(Set<Category> categories, Integer[] expectedIds) {
|
||||
|
|
Loading…
Reference in New Issue