Difference between revisions of "Talk:EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Additional Criteria"
m (Talk:EclipseLink/UserGuide/JPA/Basic JPA Development/Querying/Additional Criteria moved to Talk:EclipseLink/UserGuide/JPA/Basic JPA Development/Mapping/Additional Criteria over redirect)
|(One intermediate revision by the same user not shown)|
Latest revision as of 14:07, 21 April 2011
- Documentation should be from JPA perspective, not native API, do not talk about descriptors, expressions etc., talk about Entities, Queries. [fixed - bg]
- Merging and overriding applies to all annotations/xml, should not document it in here or in every page, but have a single page that documents the overriding behavior. [fixed - bg]
- Examples are not use "source lang="java"/"xml"" tags. [fixed - bg]
- The example formatting is off, two lines appended to one. The example should be relevant to something that a user would want to do, i.e. ."this.isDeleted = false", or effective dates, or tenants. [fixed - bg]
- Should state the purpose of this feature, why would someone want to use it? Soft deletes, history, multi-tenancy, shared table [added -bg. But I need more information about how/why this feature is useful for those items]
- Should include link to API (annotation, maybe native API (DescriptorQueryManager, Expression))[fixed - bg]
- James.sutherland.oracle.com 19:33, 28 February 2011 (UTC)
- AdditionalCriteria is more part of mapping, than querying, should probably be in the mapping section.
- James.sutherland.oracle.com 16:52, 1 March 2011 (UTC)[fixed - bg]
Questions 4/4/11 BG Why is this useful for multi-tenancy, soft deletes, history, shared tables, and temporal filtering? Can someone provide examples, if you think that would be helpful?
- The reason for AdditionalCriteria is to support parametrized views on the user's data.
- Multi-tenancy is when you have the data for several applications/users/tenants in the same table. Each tenant only wants to see their own data.
- To do this with AdditionalCriteria, you would define @AdditionalCriteria("TENANT = 'Billing'") if you were building an application just for billing that used shared data. Or, @AdditionalCriteria("this.tenant = :tenant") if you application could be used by multiple different tenants (at the same time). When the tenant acquired its EntityManagerFactory or EntityManager it would set the persistence/entity manager property "tenant" to their name.
Map properties = new HashMap(); properties.put("tenant", "ACME"); EntityManagerFactory emf = Persistence.createEntityManagerFactory(properties);
Map properties = new HashMap(); properties.put("tenant", "ACME"); EntityManager em = factory.createEntityManager(properties);
- You might want to add a section on multi-tenancy and explain it in detail, then just reference if from here. We will have more multi-tenancy support in the 2.3 release.
- A soft delete is when user do not ever delete any data, but just mark it as deleted, so the keep a record of it.
- @AdditionalCriteria("this.isDeleted = false"), this will filter any delete data from any query.
- Again you may wish to have a section on soft deletes and reference it (can also explain how to override the deleteSQL to update the flag)
- History is when data is never removed or updated, on an update a new row is inserted with a new start/end time instead.
- We have specific history support, but if the user just wants something simpler or more generic they can use criteria.
- @AdditionalCriteria("this.endDate is null"), this will return the current data from any query
- Or you could create an EntityManager on a specific date, @AdditionalCriteria("this.startDate <= :viewDate and this.endDate >= :viewDate")
- For a shared table, you could have inheritance in the table, but not in the object model.
- i.e. you have an SavingsAccount class and an ACCOUNT table but the ACCOUNT table also has checking account data that you want filtered.
- James.sutherland.oracle.com 13:07, 5 April 2011 (UTC)