-
Notifications
You must be signed in to change notification settings - Fork 0
shaketbaby/eq4j
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
What is EQ4J? EQ4J - Entity Query for JPA - is a type safe, entity object based query API on top of JPA-QL. Why EQ4J? The problem with JPA-QL is it is String based, so the Java type system can not help here. If you have typos on field name, you wouldn't find out until you actually run it. If you want to change name, refactor won't be able to help, you have to find & replace. Yes, there is Criteria API, but it sucks. it is ugly, cumbersome, hard to use and maintain. How EQ4J works? EQ4J is built around the JPA Entity, the query is written in strong typed Java codes and eventually get translated into String based JPA-QL. for example, given an entity class: @Entity public class User { private int age; private String name; // more fields public int getAge() { return age; } public String getName() { return name; } // more codes } JPA-QL: select u from User u where u.name = :name and u.age > :age EQ4J: Select<User> select = select(); User u = select.from(User.class); select.where(u.getName(), equalsTo("some name")) .and(u.getAge(), greatThan(12)); // convert to javax.persistence.TypedQuery // can either get result or do a bit more settings TypedQuery<User> query = select.toTypedQuery(entityManager);
About
Type safe, entity object query for JPA
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published