Looking for an HQL builder (Hibernate Query Language)

后端 未结 11 911
-上瘾入骨i
-上瘾入骨i 2021-02-04 16:45

I\'m looking for a builder for HQL in Java. I want to get rid of things like:

StringBuilder builder = new StringBuilder()
    .append(\"select stock from \")
            


        
11条回答
  •  清歌不尽
    2021-02-04 17:31

    For a type-safe approach to your problem, consider Querydsl.

    The example query becomes

    HQLQuery query = new HibernateQuery(session);
    List s = query.from(stock, bonus)
      .where(stock.someValue.eq(bonus.id))
      .list(stock);
    

    Querydsl uses APT for code generation like JPA2 and supports JPA/Hibernate, JDO, SQL and Java collections.

    I am the maintainer of Querydsl, so this answer is biased.

提交回复
热议问题