My current application is an EJB 2.x system and uses Entity Beans everywhere, with CMR & CMP. I am looking to replace the persistence layer with standard JPA and I am unable to find out if the following is possible.
The system implements a logical delete by setting a column on the table VOID_IND = 'y' when the record is requested to be deleted. Current processing logic in the system will retrieve all items from the child table using the CMR and then loop and discard the ones with the VOID_IND = 'y' and only return to the client where VOID_IND = 'n'.
This seems very inefficient to me and I would rather not return these "deleted" records in the first place. Unfortunately I have only been able to find annotations that are implementation specific to help with this.
Hibernate as @Where and EclipseLink @AdditionalCriteria
But I am wondering if there are standard annotations that work specifically with JPA?
No, unfortunately no standard filter.
I think that you should create a query.
JPA includes JPQL and Criteria API, but I strongly suggest looking at QueryDSL which is really nice to work with, with typesafe autogenerated "query" classes.
Here is an example in QueryDSL; It's not that much code.
Query q = new Query();
List<Child> active = q.from(qChild)
.where(qChild.parent.eq(parent), qChild.voidInd.eq('Y'))
.list(qChild);
alternatively
q.from(qChild);
q.where(qChild.parent.eq(parent));
q.where(qChild.voidInd.eq('Y'));
List<Child> active = q.list(qChild);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With