I have two tables:
1- Device :
2- User: has foreign key to device, relation is ManyToOne.
i have list of devices and the device can be deleted if it’s not assigned to a user
so i get all devices, and check if device is assigned to a user then set transient boolean property follows:
List <Device> devices = systemSettingsDao.getAllDevices();
for (Device device : devices)
device.setDeletable(!systemSettingsDao
.isDeviceUsedByUser(device.getId()));
i was wondering if there’s more elegant way to set the boolean property with querying (criteria is preferable) without making this for loop ?
Here’s how you could get all the deletable devices:
You should be able to translate this with the Criteria API easily.