criteria-api

Why left join on CriteriaQuery doesn't filter results?

拈花ヽ惹草 提交于 2020-08-17 11:50:46
问题 I have two entities, User and Roles each one with active boolean parameter and ManyToMany relationship. This boolean parameter is used for logical delete. Why does the result include inactive Roles when I run this query below? CriteriaBuilder builder = em.getCriteriaBuilder(); CriteriaQuery<User> query = builder.createQuery(User.class); //Select Root<User> user = query.from(User.class); //Join SetJoin<User, Role> role = user.joinSet("roles", JoinType.LEFT); Predicate rolesActivePredicate =

ORDER BY in Criteria API for a computed column name (by alias)

两盒软妹~` 提交于 2020-07-31 04:14:13
问题 Having a situation where my java code is symbolic to query - SELECT CUSTOMER_ID, CUSTOMER_NAME, CASE WHEN COUNT (DISTINCT CARD_ID) > 1 THEN 'MULTIPLE' ELSE MAX(CARD_NUM) END AS CARD_NUM FROM CUSTOMER LEFT JOIN CARD ON CARD.CUSTOMER_ID = CUSTOMER.CUSTOMER_ID GROUP BY CUSTOMER_ID, CUSTOMER_NAME Java code for detailed info - CriteriaBuilder cb = em.getCriteriaBuilder(); final CriteriaQuery<Tuple> query = cb.createQuery(Tuple.class); final Root<Customer> root = query.from(Customer.class);

JPA Criteria API - where condition with field on subclass

蹲街弑〆低调 提交于 2020-07-09 05:32:10
问题 I have entity called Issue and entity called UserIssue . UserIssue extends Issue . @Inheritance(strategy = InheritanceType.JOINED) @Entity(name = "ISSUE") public class Issue extends VersionedSequenceIdEntity { ... all fields } @Entity(name = "USER_ISSUE") public class UserIssue extends Issue { ... @Enumerated(EnumType.STRING) @Column(name = "CATEGORY", nullable = false) private IssueCategory category; ... } I need to do e.g. something like this: Predicate predicate= root.get("category").in

JPA Criteria API - where condition with field on subclass

筅森魡賤 提交于 2020-07-09 05:31:53
问题 I have entity called Issue and entity called UserIssue . UserIssue extends Issue . @Inheritance(strategy = InheritanceType.JOINED) @Entity(name = "ISSUE") public class Issue extends VersionedSequenceIdEntity { ... all fields } @Entity(name = "USER_ISSUE") public class UserIssue extends Issue { ... @Enumerated(EnumType.STRING) @Column(name = "CATEGORY", nullable = false) private IssueCategory category; ... } I need to do e.g. something like this: Predicate predicate= root.get("category").in

Need to find all Users for a specific role JPA Criteria API

独自空忆成欢 提交于 2020-06-29 04:04:17
问题 I am implementing a user management system which has the following entities : public class UserEntity implements Serializable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "ID") Long id; @Column(unique = true, name = "EMAIL") private String email; @Column(name = "NAME") private String name; @Column(name = "PASSWORD") private String password; @Column(name = "MOBILE") private String mobile; @Column(name = "OWNER_ID") private String ownerId; @Column(name = "TRAINER_ID"

left join on unrelated entities using criteria api

断了今生、忘了曾经 提交于 2020-06-17 14:48:31
问题 I need to replace the below sql query having left join on 2 tables with 2 same column types by using criteriabuilder api and I am getting following error when I run the program org.hibernate.query.criteria.internal.BasicPathUsageException: Cannot join to attribute of basic type. I checked couple of blogs, examples but couldn't get much help. query that needs to be replaced: SELECT connection_name, connection_date, connection_role, a.code, a.box FROM test.connections a LEFT JOIN test.samples b

JPA Criteria api join through embedded ID

拈花ヽ惹草 提交于 2020-05-15 03:44:45
问题 I have the following entities: @Entity @Table(name = "place_revision") public class PoiRevision { @OneToMany(mappedBy = "pk.revision", cascade = {CascadeType.ALL}) private Collection<PoiRevisionCategory> categoryMapping; // ... } @Entity @Table(name = "place_revision__category") @AssociationOverrides({ @AssociationOverride(name = "pk.revision", joinColumns = @JoinColumn(name = "place_revision_id")), @AssociationOverride(name = "pk.category", joinColumns = @JoinColumn(name = "category_id")) })