hibernate.mapping.default_list_semantics (`AvailableSettings#DEFAULT_LIST_SEMANTICS`)

make LIST the default classification for List attributes with no `@OrderColumn`, etc.
This commit is contained in:
Steve Ebersole 2022-01-06 08:52:26 -06:00
parent 1beabbdf40
commit 773f3429c6
52 changed files with 541 additions and 29 deletions

View File

@ -8,6 +8,7 @@ package org.hibernate.userguide.associations;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
@ -17,10 +18,12 @@ import jakarta.persistence.Id;
import jakarta.persistence.ManyToMany;
import org.hibernate.annotations.NaturalId;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
/**
@ -36,6 +39,12 @@ public class ManyToManyBidirectionalTest extends BaseEntityManagerFunctionalTest
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void testLifecycle() {
doInJPA(this::entityManagerFactory, entityManager -> {

View File

@ -8,6 +8,8 @@ package org.hibernate.userguide.collections;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
@ -17,11 +19,13 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
@ -39,6 +43,12 @@ public class OrderedBySQLTest extends BaseEntityManagerFunctionalTestCase {
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void testLifecycle() {
doInJPA(this::entityManagerFactory, entityManager -> {

View File

@ -8,6 +8,8 @@ package org.hibernate.userguide.fetching;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
@ -18,10 +20,12 @@ import jakarta.persistence.OneToMany;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.NaturalId;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
@ -38,6 +42,12 @@ public class FetchModeJoinTest extends BaseEntityManagerFunctionalTestCase {
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void test() {
doInJPA(this::entityManagerFactory, entityManager -> {

View File

@ -8,6 +8,8 @@ package org.hibernate.userguide.fetching;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
@ -18,10 +20,12 @@ import jakarta.persistence.OneToMany;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.NaturalId;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
@ -38,6 +42,12 @@ public class FetchModeSelectTest extends BaseEntityManagerFunctionalTestCase {
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void test() {
doInJPA(this::entityManagerFactory, entityManager -> {

View File

@ -8,6 +8,8 @@ package org.hibernate.userguide.fetching;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
@ -18,10 +20,12 @@ import jakarta.persistence.OneToMany;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.NaturalId;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
@ -38,6 +42,12 @@ public class FetchModeSubselectTest extends BaseEntityManagerFunctionalTestCase
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void test() {
doInJPA(this::entityManagerFactory, entityManager -> {

View File

@ -9,6 +9,8 @@ package org.hibernate.userguide.fetching;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
@ -24,11 +26,13 @@ import jakarta.persistence.QueryHint;
import org.hibernate.annotations.ColumnTransformer;
import org.hibernate.annotations.NaturalId;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -49,6 +53,12 @@ public class GraphFetchingTest extends BaseEntityManagerFunctionalTestCase {
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void test() {
doInJPA(this::entityManagerFactory, entityManager -> {

View File

@ -8,6 +8,8 @@ package org.hibernate.userguide.pc;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
@ -24,10 +26,12 @@ import org.hibernate.Session;
import org.hibernate.annotations.Filter;
import org.hibernate.annotations.FilterDef;
import org.hibernate.annotations.ParamDef;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -47,6 +51,12 @@ public class FilterTest extends BaseEntityManagerFunctionalTestCase {
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void testLifecycle() {
doInJPA(this::entityManagerFactory, entityManager -> {

View File

@ -9,6 +9,7 @@ package org.hibernate.userguide.pc;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Entity;
@ -26,10 +27,12 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.annotations.NaturalId;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@ -48,6 +51,12 @@ public class PersistenceContextTest extends BaseEntityManagerFunctionalTestCase
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void test() {
doInJPA(this::entityManagerFactory, entityManager -> {

View File

@ -9,6 +9,8 @@ package org.hibernate.userguide.pc;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
@ -18,11 +20,13 @@ import jakarta.persistence.ManyToMany;
import org.hibernate.Session;
import org.hibernate.annotations.WhereJoinTable;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
@ -40,6 +44,12 @@ public class WhereJoinTableTest extends BaseEntityManagerFunctionalTestCase {
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void testLifecycle() {
//tag::pc-where-persistence-example[]

View File

@ -8,6 +8,8 @@ package org.hibernate.userguide.pc;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
@ -17,10 +19,12 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import org.hibernate.annotations.Where;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
@ -37,6 +41,12 @@ public class WhereTest extends BaseEntityManagerFunctionalTestCase {
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void testLifecycle() {
//tag::pc-where-persistence-example[]

View File

@ -10,6 +10,8 @@ import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@ -26,6 +28,7 @@ import org.hibernate.annotations.SQLInsert;
import org.hibernate.annotations.SQLUpdate;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
@ -33,6 +36,7 @@ import org.hibernate.testing.TestForIssue;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
@ -52,6 +56,12 @@ public class CollectionLoaderTest extends BaseEntityManagerFunctionalTestCase {
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Before
public void init() {
doInJPA(this::entityManagerFactory, entityManager -> {

View File

@ -9,6 +9,8 @@ package org.hibernate.userguide.sql;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@ -26,12 +28,14 @@ import org.hibernate.annotations.SQLUpdate;
import org.hibernate.annotations.Where;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.testing.RequiresDialect;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@ -50,6 +54,12 @@ public class CustomSQLTest extends BaseEntityManagerFunctionalTestCase {
};
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Before
public void init() {
doInJPA(this::entityManagerFactory, entityManager -> {

View File

@ -476,8 +476,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
}
return classification;
},
// for now, to follow legacy behavior
CollectionClassification.BAG
CollectionClassification.LIST
);
}

View File

@ -15,8 +15,11 @@ import org.hibernate.jpa.internal.PersistenceUnitUtilImpl;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
@ -29,11 +32,21 @@ import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Andrea Boriero
*/
@ServiceRegistry(
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class
)
)
@DomainModel(
annotatedClasses = {
CompositeIdDerivedIdWithIdClassTest.ShoppingCart.class,

View File

@ -10,6 +10,8 @@ import java.util.Iterator;
import org.hibernate.boot.MetadataBuilder;
import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.Bag;
import org.hibernate.mapping.Column;
@ -20,6 +22,7 @@ import org.hibernate.mapping.Property;
import org.hibernate.mapping.Set;
import org.hibernate.mapping.Table;
import org.hibernate.mapping.UniqueKey;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.junit4.BaseNonConfigCoreFunctionalTestCase;
import org.junit.Test;
@ -39,6 +42,12 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
metadataBuilder.applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE );
}
@Override
protected void configureStandardServiceRegistryBuilder(StandardServiceRegistryBuilder ssrb) {
super.configureStandardServiceRegistryBuilder( ssrb );
ssrb.applySetting( AvailableSettings.DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG );
}
@Test
public void testTableIndex() {
PersistentClass entity = metadata().getEntityBinding( Car.class.getName() );

View File

@ -23,7 +23,9 @@ import jakarta.persistence.criteria.Root;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -45,6 +47,7 @@ public class ManyToManyTest extends BaseCoreFunctionalTestCase {
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setProperty( AvailableSettings.DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
// configuration.setImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE );
}

View File

@ -12,6 +12,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
@ -36,6 +37,7 @@ import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Table;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.DialectChecks;
import org.hibernate.testing.RequiresDialectFeature;
@ -49,6 +51,7 @@ import org.hibernate.test.annotations.TicketComparator;
import org.junit.Assert;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
@ -570,6 +573,13 @@ public class OneToManyTest extends BaseNonConfigCoreFunctionalTestCase {
return new String[] { "org/hibernate/orm/test/annotations/onetomany/orm.xml" };
}
@Override
protected void addSettings(Map settings) {
super.addSettings( settings );
// needed for `#testListWithBagSemanticAndOrderBy`
settings.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Entity(name = "OnDeleteUnidirectionalOneToManyParent")
@jakarta.persistence.Table(name = "OneToManyParent")
public static class OnDeleteUnidirectionalOneToManyParent {

View File

@ -6,6 +6,7 @@
*/
package org.hibernate.orm.test.annotations.onetomany;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -30,6 +31,7 @@ import org.hibernate.dialect.OracleDialect;
import org.hibernate.dialect.SQLServerDialect;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.graph.RootGraph;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.query.Query;
@ -500,6 +502,7 @@ public class OrderByTest extends BaseCoreFunctionalTestCase {
@Override
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.DEFAULT_NULL_ORDERING, "last" );
configuration.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Override

View File

@ -13,10 +13,12 @@ import org.hibernate.cfg.AvailableSettings;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.Test;
import jakarta.persistence.CascadeType;
@ -29,6 +31,7 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.OrderBy;
import jakarta.persistence.Table;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@ -45,7 +48,11 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
@Setting(name = AvailableSettings.SHOW_SQL, value = "true"),
@Setting(name = AvailableSettings.FORMAT_SQL, value = "true"),
@Setting(name = AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, value = "64")
}
},
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class
)
)
public class BatchFetchReferencedColumnNameTest {

View File

@ -10,6 +10,7 @@ import org.hibernate.annotations.LazyToOne;
import org.hibernate.annotations.LazyToOneOption;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -30,6 +31,7 @@ import jakarta.persistence.Table;
import java.util.ArrayList;
import java.util.List;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.bytecode.enhancement.EnhancerTestUtils.checkDirtyTracking;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
@ -51,6 +53,7 @@ public class LazyLoadingIntegrationTest extends BaseCoreFunctionalTestCase {
protected void configure(Configuration configuration) {
configuration.setProperty( AvailableSettings.USE_SECOND_LEVEL_CACHE, "false" );
configuration.setProperty( AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, "true" );
configuration.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Before

View File

@ -7,10 +7,13 @@
package org.hibernate.orm.test.bytecode.enhancement.lazy.proxy;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.Id;
@ -18,6 +21,7 @@ import jakarta.persistence.ManyToMany;
import jakarta.persistence.Table;
import org.hibernate.LazyInitializationException;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.bytecode.enhancement.BytecodeEnhancerRunner;
@ -38,6 +42,12 @@ public class BytecodeEnhancedLazyLoadingOnDeletedEntityTest
return new Class<?>[] { AssociationOwner.class, AssociationNonOwner.class };
}
@Override
protected void addSettings(Map settings) {
super.addSettings( settings );
settings.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@After
public void tearDown() {
doInHibernate( this::sessionFactory, s -> {

View File

@ -13,6 +13,7 @@ import org.hibernate.cache.spi.access.CollectionDataAccess;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.testing.TestForIssue;
@ -21,6 +22,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@ -53,6 +55,7 @@ public class CollectionCacheEvictionTest extends BaseCoreFunctionalTestCase {
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );
cfg.setProperty( Environment.USE_QUERY_CACHE, "true" );
cfg.setProperty( Environment.CACHE_PROVIDER_CONFIG, "true" );
cfg.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Override

View File

@ -9,10 +9,12 @@ import org.hibernate.Session;
import org.hibernate.cache.internal.CollectionCacheInvalidator;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@ -45,6 +47,7 @@ public class LockModeTest extends BaseCoreFunctionalTestCase {
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );
cfg.setProperty( Environment.USE_QUERY_CACHE, "true" );
cfg.setProperty( Environment.CACHE_PROVIDER_CONFIG, "true" );
cfg.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Override

View File

@ -15,12 +15,14 @@ import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.cache.internal.CollectionCacheInvalidator;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.Assert.assertEquals;
/**
@ -49,6 +51,7 @@ public class ManyToManyCollectionCacheEvictionTest extends BaseCoreFunctionalTes
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "true" );
cfg.setProperty( Environment.USE_QUERY_CACHE, "true" );
cfg.setProperty( Environment.CACHE_PROVIDER_CONFIG, "true" );
cfg.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test

View File

@ -8,6 +8,9 @@ package org.hibernate.orm.test.collection.bag;
import java.util.ArrayList;
import java.util.List;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Column;
import jakarta.persistence.ElementCollection;
@ -20,16 +23,24 @@ import jakarta.persistence.Table;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author Gail Badner
*/
@ServiceRegistry(
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class )
)
@DomainModel(annotatedClasses = {
BagElementNullBasicTest.AnEntity.class,
BagElementNullBasicTest.NullableElementsEntity.class

View File

@ -18,17 +18,26 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import org.hibernate.loader.MultipleBagFetchException;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@ServiceRegistry(
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class )
)
@DomainModel(
annotatedClasses = {
MultipleBagFetchHqlTest.Post.class,

View File

@ -24,6 +24,7 @@ import jakarta.persistence.OneToMany;
import org.hibernate.Hibernate;
import org.hibernate.collection.spi.AbstractPersistentCollection;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.type.CollectionType;
import org.hibernate.testing.TestForIssue;
@ -31,12 +32,15 @@ import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.LoggingInspections;
import org.hibernate.testing.orm.junit.LoggingInspectionsScope;
import org.hibernate.testing.orm.junit.MessageKeyWatcher;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -47,6 +51,11 @@ import static org.junit.jupiter.api.Assertions.fail;
*
* @author Gail Badner
*/
@ServiceRegistry(
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class )
)
@DomainModel(
annotatedClasses = {
DetachedBagDelayedOperationTest.Parent.class,

View File

@ -12,8 +12,11 @@ import java.util.List;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Column;
@ -30,6 +33,7 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.orm.test.util.SchemaUtil.getColumnNames;
/**
@ -58,6 +62,12 @@ import static org.hibernate.orm.test.util.SchemaUtil.getColumnNames;
* at org.hibernate.testing.junit4.TestClassMetadata.performCallbackInvocation(TestClassMetadata.java:205)
*/
@TestForIssue(jiraKey = "HHH-13295")
@ServiceRegistry(
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class
)
)
@DomainModel(
annotatedClasses = {
EmbeddedIdWithMapsIdTargetingDerivedEntityTest.Attendance.class,

View File

@ -17,12 +17,15 @@ import jakarta.persistence.ManyToOne;
import jakarta.persistence.OrderBy;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.query.Query;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
public class OrderByEmbeddableToOneTest extends BaseCoreFunctionalTestCase {
@ -31,6 +34,12 @@ public class OrderByEmbeddableToOneTest extends BaseCoreFunctionalTestCase {
return new Class[] { Containing.class, Embed.class, Contained.class };
}
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void test() {
inTransaction( session -> {

View File

@ -17,12 +17,15 @@ import jakarta.persistence.Id;
import jakarta.persistence.OrderBy;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.query.Query;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
public class OrderByEmbeddableX2Test extends BaseCoreFunctionalTestCase {
@ -31,6 +34,12 @@ public class OrderByEmbeddableX2Test extends BaseCoreFunctionalTestCase {
return new Class[] { Containing.class, Embed.class, Contained.class };
}
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void test() {
inTransaction( session -> {

View File

@ -11,11 +11,13 @@ import java.util.List;
import org.hibernate.Session;
import org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl;
import org.hibernate.cfg.Configuration;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.Assert.assertEquals;
/**
@ -27,6 +29,7 @@ public class BadMergeHandlingTest extends BaseCoreFunctionalTestCase {
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE );
configuration.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Override

View File

@ -20,12 +20,14 @@ import org.hibernate.event.spi.PostCollectionUpdateEvent;
import org.hibernate.event.spi.PreCollectionRecreateEvent;
import org.hibernate.event.spi.PreCollectionRemoveEvent;
import org.hibernate.event.spi.PreCollectionUpdateEvent;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.junit4.ExtraAssertions.assertTyping;
import static org.junit.Assert.assertEquals;
@ -39,6 +41,7 @@ public class MergeCollectionEventTest extends BaseCoreFunctionalTestCase {
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE );
configuration.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
private AggregatedCollectionEventListener.IntegratorImpl collectionListenerIntegrator =

View File

@ -21,12 +21,14 @@ import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.FetchProfile;
import org.hibernate.cfg.Configuration;
import org.hibernate.cfg.Environment;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Assert;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@ -49,6 +51,7 @@ public class CollectionLoadedInTwoPhaseLoadTest extends BaseCoreFunctionalTestCa
public void configure(Configuration cfg) {
cfg.setProperty( Environment.GENERATE_STATISTICS, "true" );
cfg.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test

View File

@ -17,11 +17,14 @@ import java.util.TreeSet;
import org.hibernate.QueryException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.dialect.H2Dialect;
import org.hibernate.dialect.MySQLDialect;
import org.hibernate.exception.ConstraintViolationException;
import org.hibernate.id.BulkInsertionCapableIdentifierGenerator;
import org.hibernate.id.IdentifierGenerator;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.query.Query;
@ -70,6 +73,13 @@ public class BulkManipulationTest extends BaseCoreFunctionalTestCase {
return new Class<?>[] { Farm.class, Crop.class };
}
@Override
protected void prepareBasicRegistryBuilder(StandardServiceRegistryBuilder builer) {
super.prepareBasicRegistryBuilder( builer );
builer.applySetting( AvailableSettings.DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG );
}
@Test
public void testUpdateWithSubquery() {
Session s = openSession();

View File

@ -23,19 +23,29 @@ import jakarta.persistence.OneToOne;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @author Davide D'Alto
*/
@TestForIssue(jiraKey = "HHH-12332")
@ServiceRegistry(
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class
)
)
@DomainModel(
annotatedClasses = {
TablePerClassInheritancePersistTest.Family.class,

View File

@ -8,6 +8,7 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Environment;
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.type.descriptor.java.StringJavaTypeDescriptor;
import org.hibernate.type.descriptor.jdbc.JdbcType;
@ -55,6 +56,7 @@ abstract class BaseInsertOrderingTest extends BaseSessionFactoryFunctionalTest {
.get( AvailableSettings.CONNECTION_PROVIDER );
this.connectionProvider.setConnectionProvider( connectionProvider );
builer.applySetting( AvailableSettings.CONNECTION_PROVIDER, this.connectionProvider );
builer.applySetting( AvailableSettings.DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG );
}

View File

@ -29,21 +29,30 @@ import jakarta.persistence.Table;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@Jpa(annotatedClasses = {
MultiLevelCascadeCollectionEmbeddableTest.MainEntity.class,
MultiLevelCascadeCollectionEmbeddableTest.SubEntity.class,
MultiLevelCascadeCollectionEmbeddableTest.AnotherSubSubEntity.class,
MultiLevelCascadeCollectionEmbeddableTest.SubSubEntity.class
})
@Jpa(
annotatedClasses = {
MultiLevelCascadeCollectionEmbeddableTest.MainEntity.class,
MultiLevelCascadeCollectionEmbeddableTest.SubEntity.class,
MultiLevelCascadeCollectionEmbeddableTest.AnotherSubSubEntity.class,
MultiLevelCascadeCollectionEmbeddableTest.SubSubEntity.class
},
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class
)
)
public class MultiLevelCascadeCollectionEmbeddableTest {
private boolean initialized = false;

View File

@ -28,23 +28,33 @@ import jakarta.persistence.Table;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.jboss.logging.Logger;
import org.junit.jupiter.api.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@Jpa(annotatedClasses = {
MultiLevelCascadeCollectionIdClassTest.MainEntity.class,
MultiLevelCascadeCollectionIdClassTest.SubEntity.class,
MultiLevelCascadeCollectionIdClassTest.AnotherSubSubEntity.class,
MultiLevelCascadeCollectionIdClassTest.SubSubEntity.class
})
@Jpa(
annotatedClasses = {
MultiLevelCascadeCollectionIdClassTest.MainEntity.class,
MultiLevelCascadeCollectionIdClassTest.SubEntity.class,
MultiLevelCascadeCollectionIdClassTest.AnotherSubSubEntity.class,
MultiLevelCascadeCollectionIdClassTest.SubSubEntity.class
},
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class
)
)
public class MultiLevelCascadeCollectionIdClassTest {
private static final Logger log = Logger.getLogger( MultiLevelCascadeCollectionIdClassTest.class );

View File

@ -9,6 +9,7 @@ package org.hibernate.orm.test.jpa.graphs.queryhint;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import jakarta.persistence.EntityGraph;
import jakarta.persistence.EntityManager;
@ -18,6 +19,7 @@ import jakarta.persistence.Subgraph;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.jpa.QueryHints;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.orm.test.jpa.BaseEntityManagerFunctionalTestCase;
import org.hibernate.orm.test.jpa.graphs.Company;
import org.hibernate.orm.test.jpa.graphs.CompanyFetchProfile;
@ -32,6 +34,7 @@ import org.hibernate.testing.TestForIssue;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInJPA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -534,4 +537,10 @@ public class QueryHintEntityGraphTest extends BaseEntityManagerFunctionalTestCas
protected Class<?>[] getAnnotatedClasses() {
return new Class<?>[] { Company.class, CompanyFetchProfile.class, Employee.class, Manager.class, Location.class, Course.class, Student.class };
}
@Override
protected void addConfigOptions(Map options) {
super.addConfigOptions( options );
options.put( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG );
}
}

View File

@ -20,11 +20,15 @@ import org.hibernate.annotations.NaturalId;
import org.hibernate.dialect.TiDBDialect;
import org.hibernate.testing.orm.junit.EntityManagerFactoryScope;
import org.hibernate.testing.orm.junit.FailureExpected;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.testing.orm.junit.Jpa;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.hibernate.testing.orm.junit.SkipForDialect;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
/**
* @author Vlad Mihalcea
*/
@ -32,7 +36,11 @@ import org.junit.jupiter.api.Test;
annotatedClasses = {
ManyToManyBidirectionalTest.Person.class,
ManyToManyBidirectionalTest.Address.class,
}
},
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class
)
)
public class ManyToManyBidirectionalTest {

View File

@ -10,12 +10,16 @@ import java.util.Collection;
import java.util.List;
import org.hibernate.annotations.CollectionClassificationType;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.mapping.Bag;
import org.hibernate.mapping.Property;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Basic;
@ -25,17 +29,31 @@ import jakarta.persistence.Id;
import jakarta.persistence.Table;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
/**
* Explicitly sets {@link AvailableSettings#DEFAULT_LIST_SEMANTICS} to BAG
* and verifies the outcome.
*
* Basically verifies that the legacy behavior can be achieved via the setting
* for users migrating who wish to retain that legacy behavior
*
* @author Steve Ebersole
*/
@ServiceRegistry(
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class
)
)
@DomainModel( annotatedClasses = ImplicitListAsBagSemanticsTests.AnEntity.class )
public class ImplicitListAsBagSemanticsTests {
@Test
void verifyModel(DomainModelScope scope) {
scope.withHierarchy( AnEntity.class, (descriptor) -> {
final Property implicitList = descriptor.getProperty( "implicitList" );
// because of missing `AvailableSettings.DEFAULT_LIST_SEMANTICS`, this should be BAG (legacy)
// this is the purpose of the new AvailableSettings#DEFAULT_LIST_SEMANTICS
// setting to allow legacy behavior.
assertThat( implicitList.getValue() ).isInstanceOf( Bag.class );
final Property implicitBag = descriptor.getProperty( "implicitBag" );
@ -92,4 +110,5 @@ public class ImplicitListAsBagSemanticsTests {
this.name = name;
}
}
}

View File

@ -0,0 +1,100 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.orm.test.mapping.collections;
import java.util.Collection;
import java.util.List;
import org.hibernate.annotations.CollectionClassificationType;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.mapping.Bag;
import org.hibernate.mapping.Property;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.DomainModelScope;
import org.junit.jupiter.api.Test;
import jakarta.persistence.Basic;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Uses the default {@link AvailableSettings#DEFAULT_LIST_SEMANTICS} value of LIST
* and verifies the outcome
*
* @author Steve Ebersole
*/
@DomainModel( annotatedClasses = ImplicitListDefaultSemanticsTests.AnEntity.class )
public class ImplicitListDefaultSemanticsTests {
@Test
void verifyModel(DomainModelScope scope) {
scope.withHierarchy( AnEntity.class, (descriptor) -> {
final Property implicitList = descriptor.getProperty( "implicitList" );
// this is the change related to AvailableSettings#DEFAULT_LIST_SEMANTICS
// previous versions interpreted these as BAG
assertThat( implicitList.getValue() ).isInstanceOf( org.hibernate.mapping.List.class );
final Property implicitBag = descriptor.getProperty( "implicitBag" );
assertThat( implicitBag.getValue() ).isInstanceOf( Bag.class );
final Property explicitBag = descriptor.getProperty( "explicitBag" );
assertThat( explicitBag.getValue() ).isInstanceOf( Bag.class );
final Property explicitList = descriptor.getProperty( "explicitList" );
assertThat( explicitList.getValue() ).isInstanceOf( org.hibernate.mapping.List.class );
} );
}
@Entity( name = "AnEntity" )
@Table( name = "t_entity" )
public static class AnEntity {
@Id
private Integer id;
@Basic
private String name;
@ElementCollection
private List<String> implicitList;
@ElementCollection
private Collection<String> implicitBag;
@ElementCollection
@CollectionClassificationType( CollectionClassification.BAG )
private List<String> explicitBag;
@ElementCollection
@CollectionClassificationType( CollectionClassification.LIST )
private List<String> explicitList;
private AnEntity() {
// for use by Hibernate
}
public AnEntity(Integer id, String name) {
this.id = id;
this.name = name;
}
public Integer getId() {
return id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}

View File

@ -589,7 +589,6 @@ public class OneToManyBidirectionalTest {
}
@Test
@FailureExpected(jiraKey = "no jira", reason = "order.getLineItems().size() is 4 and not 2 as it should be")
public void testItemFetchJoin(SessionFactoryScope scope) {
SQLStatementInspector sqlStatementInterceptor = (SQLStatementInspector) scope.getStatementInspector();
scope.inTransaction( session -> {

View File

@ -17,23 +17,32 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import org.hibernate.collection.spi.PersistentBag;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.stat.spi.StatisticsImplementor;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Andrea Boriero
*/
@ServiceRegistry(
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class )
)
@DomainModel(
annotatedClasses = {
OneToManyEmptyCollectionTest.Order.class,

View File

@ -14,6 +14,8 @@ import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.BaseUnitTest;
@ -42,7 +44,9 @@ public class ComponentNamingStrategyForJoinColumnTest {
@Test
public void testNamingComponentPath() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG )
.build();
try {
final MetadataSources ms = new MetadataSources( ssr )

View File

@ -12,11 +12,13 @@ import org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl;
import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
import org.hibernate.boot.registry.StandardServiceRegistry;
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.mapping.Bag;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.orm.junit.BaseUnitTest;
@ -34,7 +36,9 @@ public class ComponentNamingStrategyTest {
@Test
public void testDefaultNamingStrategy() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG )
.build();
try {
final MetadataSources ms = new MetadataSources( ssr );
@ -60,7 +64,9 @@ public class ComponentNamingStrategyTest {
@Test
@TestForIssue( jiraKey = "HHH-6005" )
public void testComponentSafeNamingStrategy() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
.applySetting( AvailableSettings.DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG )
.build();
try {
final MetadataSources ms = new MetadataSources( ssr );

View File

@ -30,15 +30,18 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.testing.orm.junit.DomainModel;
import org.hibernate.testing.orm.junit.ImplicitListAsBagProvider;
import org.hibernate.testing.orm.junit.ServiceRegistry;
import org.hibernate.testing.orm.junit.SessionFactory;
import org.hibernate.testing.orm.junit.SessionFactoryScope;
import org.hibernate.testing.orm.junit.Setting;
import org.hibernate.testing.orm.junit.SettingProvider;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@ -46,6 +49,18 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Janario Oliveira
*/
@ServiceRegistry(
settings = {
@Setting(name = AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, value = "true"),
@Setting(name = Environment.USE_SECOND_LEVEL_CACHE, value = "true"),
@Setting(name = Environment.USE_QUERY_CACHE, value = "true"),
@Setting(name = Environment.CACHE_PROVIDER_CONFIG, value = "true"),
},
settingProviders = @SettingProvider(
settingName = DEFAULT_LIST_SEMANTICS,
provider = ImplicitListAsBagProvider.class
)
)
@DomainModel(
annotatedClasses = {
CacheLazyLoadNoTransTest.Application.class,
@ -54,14 +69,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
}
)
@SessionFactory
@ServiceRegistry(
settings = {
@Setting(name = AvailableSettings.ENABLE_LAZY_LOAD_NO_TRANS, value = "true"),
@Setting(name = Environment.USE_SECOND_LEVEL_CACHE, value = "true"),
@Setting(name = Environment.USE_QUERY_CACHE, value = "true"),
@Setting(name = Environment.CACHE_PROVIDER_CONFIG, value = "true"),
}
)
public class CacheLazyLoadNoTransTest {
@AfterEach

View File

@ -9,10 +9,13 @@ package org.hibernate.orm.test.unidir;
import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -38,6 +41,12 @@ public class BackrefTest extends BaseCoreFunctionalTestCase {
return new Class<?>[] { Parent1.class, Child1.class, Child2.class };
}
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Test
public void testBackRef() {
Session s = openSession();

View File

@ -24,6 +24,8 @@ import org.hibernate.Hibernate;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.Where;
import org.hibernate.annotations.WhereJoinTable;
import org.hibernate.cfg.Configuration;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -31,6 +33,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -48,6 +51,12 @@ public class LazyManyToManyNonUniqueIdWhereTest extends BaseCoreFunctionalTestCa
return new Class[] { Material.class, Building.class, Rating.class, Size.class };
}
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Before
public void setup() {
doInHibernate(

View File

@ -21,6 +21,8 @@ import jakarta.persistence.Table;
import org.hibernate.Hibernate;
import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.Where;
import org.hibernate.cfg.Configuration;
import org.hibernate.metamodel.CollectionClassification;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
@ -28,6 +30,7 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.hibernate.cfg.AvailableSettings.DEFAULT_LIST_SEMANTICS;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@ -45,6 +48,12 @@ public class LazyOneToManyNonUniqueIdWhereTest extends BaseCoreFunctionalTestCas
return new Class[] { Material.class, Building.class, Rating.class, Size.class };
}
@Override
protected void configure(Configuration configuration) {
super.configure( configuration );
configuration.setProperty( DEFAULT_LIST_SEMANTICS, CollectionClassification.BAG.name() );
}
@Before
public void setup() {
doInHibernate(

View File

@ -21,3 +21,6 @@ hibernate.cache.region_prefix hibernate.test
hibernate.cache.region.factory_class org.hibernate.testing.cache.CachingRegionFactory
hibernate.service.allow_crawling=false
## backwards compatibility wrt bag v. list for "implicit" List mappings
hibernate.mapping.default_list_semantics=bag

View File

@ -0,0 +1,30 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
package org.hibernate.testing.orm.junit;
import org.hibernate.metamodel.CollectionClassification;
/**
* Used as a SettingProvider to enable backwards compatibility regarding
* plural {@link java.util.List} mappings when no {@link jakarta.persistence.OrderColumn},
* {@link org.hibernate.annotations.ListIndexBase},
* {@link org.hibernate.annotations.CollectionId} or other annotations hinting at
* the classification to use.
*
* Historically, Hibernate classified these as BAG. 6.0 changes that to LIST (with an
* implied {@link jakarta.persistence.OrderColumn}).
*
* This setting provider is used to enable the legacy classification
*
* @author Steve Ebersole
*/
public class ImplicitListAsBagProvider implements SettingProvider.Provider<CollectionClassification> {
@Override
public CollectionClassification getSetting() {
return CollectionClassification.BAG;
}
}