Like fails if both underscore and percent are used


When using a like query that has both _ and % in it, ObjectDB seems to fail.

Here is a unit test to demonstrate:


import org.junit.*;

import javax.persistence.*;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import java.util.List;

import static org.junit.Assert.*;

public class LikeTest {

    public static class StringHolder
        public Long id;

        public String content;

        public StringHolder(String content)
            this.content = content;

    private EntityManagerFactory emf;
    private EntityManager em;

    public void setUp()
        emf = Persistence.createEntityManagerFactory("./foo.odb");
        em = emf.createEntityManager();

        for(StringHolder item : getAll())

    public void likeTest()
        StringHolder entry = new StringHolder("foobar");
        assertEquals(0, getAll().size()); //DB is empty

        assertEquals(1, getAll().size()); //Save was successful

        final String queryString = "SELECT holder FROM StringHolder holder WHERE holder.content LIKE :filter";
        Query query = em.createQuery(queryString, StringHolder.class);

        query.setParameter("filter", "_oo%");
        List results = query.getResultList();
        assertEquals(1, results.size());

    private List<StringHolder> getAll()
        CriteriaBuilder builder = em.getCriteriaBuilder();

        CriteriaQuery<StringHolder> query = builder.createQuery(StringHolder.class);
        Root<StringHolder> c = query.from(StringHolder.class);
        query =;
        return em.createQuery(query).getResultList();

Thank you for this report and for the clear test case.

Please try build 2.5.4_03, which should fix this bug.

ObjectDB Support
ObjectDB - Fast Object Database for Java (JPA/JDO)

Confirmed. Fixes both this test case and my internal one

Post Reply

To post a reply and/or subscribe to update notifications - please login