I have an employee view. I have no insight as to how the data for the view is collected but I know it comes from multiple tables.
The view has columns for employeeId and supervisorId. Among other things the JPA Employee class has the following (names modified here for readability):
Here comes the interesting bit:
@GeneratedValue(strategy = GenerationType.AUTO)
private String employeeId;
@JoinColumn(name="supervisorId", nullable=true, insertable=false, updatable=false)
private Employee supervisor;
private Set<Employee> employees = new HashSet<Employee>(0);
1) The "big cheese" has employeeId = "999999999".
2) The person right below him obviously has supervisorId="999999999".
3) The record for the "big cheese" happens to be missing in a DEV database. Yes, I realize this is corrupt.
4) The employee view was recently modified (no, I don't have access to it). The old version allowed us to query the tree of supervisors from anyone up to the top, without a problem even though we had a broken relationship between the #2 person and the "big cheese" due to the missing big cheese.
5) The revised version of the view causes an exception to be thrown by Hibernate itself (not our processing code) because of the broken relationship.
a) Without seeing the view's code (which I can't see myself) can anyone think of why one version of the view would work while other one doesn't?
b) Is there any way to prevent JPA/Hibernate from throwing an exception when it sees a supervisorId="9999999" and fails to find the Employee with employeeId of the same value?
Before badgering me about the data being defective, please understand that I have no control over it, but I am expected to keep the applications from blowing up even when users do very stupid things like this one. To add to the problem... the data entry is done through an application that I have absolutely no control over, so I couldn't put edit checks to prevent bad data even if I wanted to.