New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiply QuerySyntaxException after Update from 2.9.0 to 3.2.1 #462

Closed
bennixview opened this Issue Jul 26, 2013 · 9 comments

Comments

Projects
None yet
3 participants
@bennixview

bennixview commented Jul 26, 2013

Hello,

after a change from 2.9.0 to 3.2.1 I get the following QuerySyntaxException,
Also, I get a NPE when using Expressions.constant :
(hibernate 4.1.5.Final)

java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1, column 47 [select case when baa.einheit = ?1 then baa.id * ?2 when baa.einheit = ?3 then baa.id * ?4 else baa.id end
from de...............Baa baa]
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1364)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:294)
at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:129)
at com.mysema.query.jpa.impl.AbstractJPAQuery.createQuery(AbstractJPAQuery.java:97)
at com.mysema.query.jpa.impl.AbstractJPAQuery.list(AbstractJPAQuery.java:240)

You can Test ist with the following TestCase:

public class QueryDSL_Test_IT {

private static EntityManagerFactory emf;

protected static Map<String, String> createDefaultJpaProperties() {
    Map<String, String> jpaProperties = new HashMap<>();
    jpaProperties.put(AvailableSettings.HBM2DDL_AUTO, "update");
    jpaProperties.put(AvailableSettings.DIALECT, ImprovedH2Dialect.class.getName());
    jpaProperties.put("hibernate.search.autoregister_listeners", "false");
    jpaProperties.put("javax.persistence.validation.mode", "none");
    return jpaProperties;
}


public static EntityManagerFactory createDefaultEntityManagerFactory(String packagesToScan)
{
    LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
    factoryBean.setPersistenceProviderClass(HibernatePersistence.class);
    factoryBean.setJpaPropertyMap(createDefaultJpaProperties());
    factoryBean.setPersistenceUnitName("default");
    factoryBean.setPackagesToScan(packagesToScan);
    factoryBean.setDataSource(createInMemoryDataSource());
    factoryBean.afterPropertiesSet();
    return factoryBean.getNativeEntityManagerFactory();
}

private static DataSource createInMemoryDataSource() {
    return new SingleConnectionDataSource("jdbc:h2:mem:;", true);
}


private EntityManager em;

private JPAQuery sut;



@BeforeClass
public static void beforeClass() throws InterruptedException {
    emf = createDefaultEntityManagerFactory(
            Baa.class.getPackage().getName());


}



@Before
public void before() {

    em = emf.createEntityManager();
    em.getTransaction().begin();


    sut = new JPAQuery(em);
    em.persist(new Baa("2", TestEinheit.TAG_24, "Me"));
    em.persist(new Baa("3", TestEinheit.MINUTE, "Me"));
    em.persist(new Baa("4", TestEinheit.STUNDE, "Me"));



}

@After
public void after() {
    try {
        if (em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
    } finally {
        em.close();
    }
}


@Ignore
@Test
public void test_case_multiply_QuerySyntaxExceptionUnexpectedToken() {



    QBaa qbaa = QBaa.baa;

    List<Long> minutes = sut.from(qbaa).list(
            cases().when(qbaa.einheit.eq(TestEinheit.TAG_24)).then(qbaa.id.multiply(10))
                    .when(qbaa.einheit.eq(TestEinheit.MINUTE)).then(qbaa.id.multiply(5L))
                    .otherwise(qbaa.id)
    );

    for (Long minute : minutes) {
        System.out.println(minute);
    }
}

@Ignore
@Test
public void constant_test_NPE() {
    QBaa qbaa = QBaa.baa;

    Map<Long, String> map =sut.from(qbaa).map(qbaa.id, Expressions.constant("name"));

    for (Map.Entry entry : map.entrySet()) {
        System.out.println(entry.toString());
    }
}







private StringExpression constant(String string) {
    return StringTemplate.create("const({0})", Expressions.constant(string));
}


public static class Zwischenergebnis {
    private String wert;
    private String wert2;
    private Long id;

    public Zwischenergebnis() {

    }

    public String getWert() {
        return wert;
    }

    public void setWert(String wert) {
        this.wert = wert;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getWert2() {
        return wert2;
    }

    public void setWert2(String wert2) {
        this.wert2 = wert2;
    }
}

}

@entity
public class Baa implements Serializable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false)
private Long id;

private String name;

private TestEinheit einheit;

private String aendUser;


public Baa(String name, TestEinheit einheit, String aendUser) {
    this.name = name;
    this.einheit = einheit;
    this.aendUser = aendUser;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public TestEinheit getEinheit() {
    return einheit;
}

public void setEinheit(TestEinheit einheit) {
    this.einheit = einheit;
}

public String getAendUser() {
    return aendUser;
}

public void setAendUser(String aendUser) {
    this.aendUser = aendUser;
}

}

public enum TestEinheit {
TAG_24,
MINUTE,
STUNDE
}

@wrungel

This comment has been minimized.

Show comment
Hide comment
@wrungel

wrungel Jul 26, 2013

I added a Maven project to github;
https://github.com/wrungel/qdsl-bugs/tree/master/462
The test method test_case_multiply_QuerySyntaxExceptionUnexpectedToken() runs successfully with QueryDSL Version 2.9.0 but fails with Version > 3.0.0

wrungel commented Jul 26, 2013

I added a Maven project to github;
https://github.com/wrungel/qdsl-bugs/tree/master/462
The test method test_case_multiply_QuerySyntaxExceptionUnexpectedToken() runs successfully with QueryDSL Version 2.9.0 but fails with Version > 3.0.0

@wrungel

This comment has been minimized.

Show comment
Hide comment
@wrungel

wrungel Jul 26, 2013

Below are the differences in debug output of the same query using different QueryDSL versions:

  • [2.9.0] JPAQuery:300 - select case when (baa.einheit = ?1) then (baa.id * ?2) when (baa.einheit = ?3) then (baa.id * ?4) else baa.id end from Baa baa
  • [3.2.1] JPAQuery:273 - select case when baa.einheit = ?1 then baa.id * ?2 when baa.einheit = ?3 then baa.id * ?4 else baa.id end from Baa baa

wrungel commented Jul 26, 2013

Below are the differences in debug output of the same query using different QueryDSL versions:

  • [2.9.0] JPAQuery:300 - select case when (baa.einheit = ?1) then (baa.id * ?2) when (baa.einheit = ?3) then (baa.id * ?4) else baa.id end from Baa baa
  • [3.2.1] JPAQuery:273 - select case when baa.einheit = ?1 then baa.id * ?2 when baa.einheit = ?3 then baa.id * ?4 else baa.id end from Baa baa
@wrungel

This comment has been minimized.

Show comment
Hide comment
@wrungel

wrungel Jul 26, 2013

I fixed this error in repository just forked from the original master repository:
wrungel@d2ba98d
Probably this is rather workaround than a solution, but at least this works in my JPA project and the Unit tests in querydsl-jpa project are running successfully as well.

wrungel commented Jul 26, 2013

I fixed this error in repository just forked from the original master repository:
wrungel@d2ba98d
Probably this is rather workaround than a solution, but at least this works in my JPA project and the Unit tests in querydsl-jpa project are running successfully as well.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 27, 2013

Member

The case-when issue has been fixed now, but the NPE is an Hibernate bug.

Could you try the latest SNAPSHOT?

Member

timowest commented Jul 27, 2013

The case-when issue has been fixed now, but the NPE is an Hibernate bug.

Could you try the latest SNAPSHOT?

@wrungel

This comment has been minimized.

Show comment
Hide comment
@wrungel

wrungel Jul 29, 2013

Thank you very much! It works with the latest SNAPSHOT!
When do you plan to release it?

wrungel commented Jul 29, 2013

Thank you very much! It works with the latest SNAPSHOT!
When do you plan to release it?

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 29, 2013

Member

I plan to release it this week.

Member

timowest commented Jul 29, 2013

I plan to release it this week.

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 29, 2013

Member

Released in 3.2.2

Member

timowest commented Jul 29, 2013

Released in 3.2.2

@timowest timowest closed this Jul 29, 2013

@wrungel

This comment has been minimized.

Show comment
Hide comment
@wrungel

wrungel Jul 31, 2013

When the release 3.2.2 is expected to be available in Maven Central Repository?

wrungel commented Jul 31, 2013

When the release 3.2.2 is expected to be available in Maven Central Repository?

@timowest

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Jul 31, 2013

Member

It is available now.

Member

timowest commented Jul 31, 2013

It is available now.

@timowest timowest added this to the 3.2.2 milestone Apr 14, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment