Search code examples
hibernatehibernate-criteriadetachedcriteria

Hibernate Criteria and metamodel


I could not find anywhere if it possible to create metamodel over entites to be used in Hibernate's Criteria API. So I don't have to write strings for fields, but rather rely on the generated metamodel similarly as it can be done with JPA Criteria API.

I noticed that only Strings can be used as parameters in the Hibernate Criteria, so I guess it's not possible?


Solution

  • Take a look at these libraries:

    www.querydsl.com

    from(user)
    .leftJoin(tweet).on(user.id.eq(tweet.posterId))
    .groupBy(user.username)
    .list(Projections.constructor(UserInfo.class, user.username, tweet.id.count()));
    

    www.jooq.org

    dsl.insertInto(BOOK)
    .set(BOOK.ID, id)
    .set(BOOK.AUTHOR_ID, authorId)
    .set(BOOK.TITLE, title)
    .execute();