I want to get a list of Persons with their addresses. But for any person if he has more than 3 addresses I want the Query to get just 3 addresses and ignore the others.
@Entity
public class Person {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private String id;
@ElementCollection(targetClass = java.util.ArrayList.class, fetch = FetchType.LAZY)
private List<Address> Addresses= new ArrayList<>();
}
You can limit the result set like that, however I feel like it is not a proper way to handle it.
@BatchSize(size = 3)
@ElementCollection(targetClass = java.util.ArrayList.class, fetch = FetchType.LAZY)
private List<Address> Addresses= new ArrayList<>();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.