Hi,
congratulations for the new H2 release!!

I tested the new release and have a problem with JPA/hibernate.
When I use an entity with a boolean field and I use this field in a 
predicate of a query I get the exception:
org.h2.jdbc.JdbcSQLSyntaxErrorException: Values of types "BOOLEAN" and 
"INTEGER" are not comparable

The test runs fine with H2 1.4.200.

Attached you find the small test case.

I use the following hibernate dependency:
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.4.30.Final</version>
        </dependency>

Can you please check if if's a regression or if I made a mistake?
Thanks!
Ulrich

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/h2-database/ff5da5dc-05e1-441d-9ca5-e6c2a3e19d02n%40googlegroups.com.
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Persistence;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

@Entity
public class H2HibernateTest
{
	@Id
	@GeneratedValue(generator = "increment")
	private int id;
	private boolean testFlag;

	public H2HibernateTest()
	{
	}

	public boolean isTestFlag()
	{
		return this.testFlag;
	}

	public void setTestFlag(boolean testFlag)
	{
		this.testFlag = testFlag;
	}

	public int getId()
	{
		return this.id;
	}

	@Override
	public String toString()
	{
		return this.id + ":" + this.testFlag;
	}

	private static void createTestData(EntityManagerFactory emf)
	{
		System.out.println("Create entities with a boolean field");

		EntityManager em = emf.createEntityManager();

		H2HibernateTest testObj = new H2HibernateTest();
		testObj.setTestFlag(false);
		em.getTransaction().begin();
		em.persist(testObj);
		em.getTransaction().commit();

		H2HibernateTest testObj2 = new H2HibernateTest();
		testObj2.setTestFlag(true);
		em.getTransaction().begin();
		em.persist(testObj2);
		em.getTransaction().commit();

		em.close();
	}

	private static void runQuery(EntityManagerFactory emf)
	{
		System.out.println("Run query using the flag");
		EntityManager em = emf.createEntityManager();
		try
		{

			CriteriaBuilder criteriaBuilder = em.getCriteriaBuilder();
			CriteriaQuery<H2HibernateTest> criteriaQuery = criteriaBuilder.createQuery(H2HibernateTest.class);
			Root<H2HibernateTest> itemRoot = criteriaQuery.from(H2HibernateTest.class);

			Predicate predicate = criteriaBuilder.isFalse(itemRoot.get("testFlag"));

			criteriaQuery.where(predicate);

			em.createQuery(criteriaQuery).getResultList().forEach(i -> System.out.println(i));
		}
		finally
		{
			em.close();
		}
	}

	public static void main(String[] args)
	{
		EntityManagerFactory emf = Persistence.createEntityManagerFactory("h2test");

		createTestData(emf);
		runQuery(emf);

		emf.close();
	}

}
<persistence xmlns="http://java.sun.com/xml/ns/persistence";
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd";
             version="2.0">

    <persistence-unit name="h2test">
        <properties>
            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:h2:file:c:/temp/test" />
            <property name="javax.persistence.jdbc.user" value="test" />
            <property name="javax.persistence.jdbc.password" value="test" />
            
 			<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
 			<property name="hibernate.hbm2ddl.auto" value="create" />
 			<property name="hibernate.show_sql" value="true" />
        </properties>

    </persistence-unit>

</persistence>

Reply via email to