Looking for an HQL builder (Hibernate Query Language)

后端 未结 11 1106
-上瘾入骨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:37

    For another type-safe query dsl, I recommend http://www.torpedoquery.org. The library is still young but it provides type safety by directly using your entity's classes. This means early compiler errors when the query no longer applies before of refactoring or redesign.

    I also provided you with an example. I think from your posts that you where trying to do a subquery restriction, so I based the exemple on that:

    import static org.torpedoquery.jpa.Torpedo.*;
    
    Bonus bonus = from(Bonus.class);
    Query subQuery = select(bonus.getId());
    
    Stock stock = from(Stock.class);
    where(stock.getSomeValue()).in(subQuery);
    
    List stocks = select(stock).list(entityManager);
    

提交回复
热议问题