speedment / jpa-streamer

JPAstreamer is a lightweight library for expressing JPA queries as Java Streams
GNU Lesser General Public License v2.1
345 stars 35 forks source link

How to use the filter / sort operation for Entity classes having @EmbeddedId composite key #208

Open ParthaNath28 opened 2 years ago

ParthaNath28 commented 2 years ago

Hello

As discussed in the Gitter Channel I would like to know the syntax to be used while working entity classes having @EmbeddedId composite key based objects.

jpaStreamer.stream(MyOwnEntity.class) .filter(MyOwnEntity$.<do I put property of nested composite key object ?>.equalIgnoreCase("filterIdentifier"))

ParthaNath28 commented 2 years ago

@Embeddable public class EmployeeId implements Serializable {

@Column(name = "company_id")
private Long companyId;

@Column(name = "employee_number")
private Long employeeNumber;

}

@Entity(name = "Employee") @Table(name = "employee") public class EmployeeEntity {

@EmbeddedId
private EmployeeId id;

private String name;

}

There can be scenario that distinct employees might not be identified by their employee id but a composite id needs be used with a combination of employee id and company id. However I might functionality to find all employees having employee number 12345. Had it been a linear Entity class structure the jpaStreamer code might have looked liked the following.

final List employeeList= jpaStreamer.stream(EmployeeEntity.class) .filter(EmployeeEntity$.employeeNumber.equalIgnoreCase()) .toList();