diff --git a/hibernate-core/src/test/java/org/hibernate/test/booleans/BooleanMappingTest.java b/hibernate-core/src/test/java/org/hibernate/test/booleans/BooleanMappingTest.java new file mode 100644 index 0000000000..adf08a0f7e --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/booleans/BooleanMappingTest.java @@ -0,0 +1,61 @@ +/* + * 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 . + */ +package org.hibernate.test.booleans; + +import java.util.List; + +import org.hibernate.testing.TestForIssue; +import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; +import org.junit.Test; + +import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * Useful to verify Boolean mappings; in particular we had a new + * error on recent versions of H2, so let's ensure this works + * on whatever version the testsuite is being run with. + */ +public class BooleanMappingTest extends BaseCoreFunctionalTestCase { + + @Test + @TestForIssue(jiraKey = "HHH-15002") + public void testFetchEager() { + doInHibernate( this::sessionFactory, s -> { + Event activeEvent = new Event(); + activeEvent.setActive( Boolean.TRUE ); + s.persist( activeEvent ); + + Event inactiveEvent = new Event(); + inactiveEvent.setActive( Boolean.FALSE ); + s.persist( inactiveEvent ); + } ); + + final List activeEvents = doInHibernate( this::sessionFactory, s -> { + return s.createQuery( "SELECT e FROM Event e WHERE e.active = true", Event.class ).getResultList(); + } ); + + assertNotNull( activeEvents ); + assertEquals( 1, activeEvents.size() ); + + final List allEvents = doInHibernate( this::sessionFactory, s -> { + return s.createQuery( "FROM Event", Event.class ).getResultList(); + } ); + + assertNotNull( allEvents ); + assertEquals( 2, allEvents.size() ); + } + + @Override + protected Class[] getAnnotatedClasses() { + return new Class[] { + Event.class, + }; + } + +} diff --git a/hibernate-core/src/test/java/org/hibernate/test/booleans/Event.java b/hibernate-core/src/test/java/org/hibernate/test/booleans/Event.java new file mode 100644 index 0000000000..37503f3e28 --- /dev/null +++ b/hibernate-core/src/test/java/org/hibernate/test/booleans/Event.java @@ -0,0 +1,38 @@ +/* + * 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 . + */ +package org.hibernate.test.booleans; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class Event { + + @Id + @GeneratedValue + private Long id; + + private Boolean active; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Boolean getActive() { + return active; + } + + public void setActive(Boolean active) { + this.active = active; + } + +}