• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Hibernate Filter (with outer join) using Annotations on OneToMany relationship

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am attempting to write a Rest Service to access some data using Hibernate. This is a little complicated to explain, so I am going to try and use an example. If you have the following tables (not a real scenario, so forgive the illogical business logic):
- Company
- Employee (Many Employees per Company)
- Project
- EmployeeProject (Really a Many To Many between Employees and Project, but treated as a 1:M from both tables)
- User (This has an optional relationship to the EmployeeProject table, i.e. the user_id (PK) is nullable in EmployeeProject - This is an important relationship to the question)

- I can read the company by name and retrieve all of the employees and in turn can read all of the projects for each employee using something like the following (Please excuse any java typos or errors since all of this is working and this is just to setup my question):



My question is, I want to add a Filter so that the results returned from the employee.getProjectEmployees() is restricted so that the only rows returned are ones in which the user is null or the user is the person executing the query. Just for clarity, I am using annotations on everything, so please restrict the answers to use annotations (unless of course this is impossible with annotations). I understand how to use the Filter, so we can skip that part, but I have been unable to figure out how to define the filter correctly. I can get simple Filters to work, but I don't know how to define a Filter that includes the User table (and in addition, an outer join to that table) in the getProjectEmployees call (since it is not a part of the access to begin with). In addition, I can't figure out which Entity the Filter should be defined on (I assume the Employee, but any reference to projectEmployee.user seems to fail). Any help would be greatly appreciated.
 
For my next feat, I will require a volunteer from the audience! Perhaps this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic