Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generic where column in JPA join

 
John Hellier
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a column called "active" in most of my tables and I would like to apply a generic where active=true to the all the joins without explicitly declaring it in each where down through the select. Ideally in the Join column annotation there would be an attribute that would allow qualifying that join such that it only ever comes back with the defined where for all tables, in this case where active=true. Since I am not explicitly describing the join tables in the actual select statement, passing in a where for each join would not work.

Ex.

Class Person
List Addresses

Class Address

Database has tables: Person, Address, PersonAddress



In this case a person has many addresses, most not active. Given the proper JPA annotations, a query to Person will give me the list of addresses for that person. I only want the active addresses for this relationship. Does anyone know how to do this without explicitly declaring active=true for all joins? This is a contrived example, because it would not make sense to not want to see all the addresses even though most would be inactive, but the requirement is that I only want the active ones, especially because there are likely to be a lot of inactive ones. Any thoughts?

Thanks

 
John Hellier
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Additional note: The subject should be "Generic where column in implicit JPA join"
 
John Hellier
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I was wrong about the implicit join. What I mean is that the query that you put in for person is just "select p from person p" and that also gets the addresses as a collection.
 
John Hellier
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since this case is using EclispeLink this can be resolved through the use of EclipseLink's additionalCritieria annotation.

http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Additional_Criteria

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic