permaculture playing cards*
The moose likes Object Relational Mapping and the fly likes Hibernate Filter (with outer join) using Annotations on OneToMany relationship Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate Filter (with outer join) using Annotations on OneToMany relationship " Watch "Hibernate Filter (with outer join) using Annotations on OneToMany relationship " New topic
Author

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

Mark Yearick
Greenhorn

Joined: Mar 08, 2013
Posts: 1
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate Filter (with outer join) using Annotations on OneToMany relationship
 
Similar Threads
Doubt regarding joins in SQL...
Hibernate: cascade deletion of a many-to-many relationship
composite-id, one-to-one, formula, and an outer join
question about Enity mapping
Hibernate: table per class inheritance