I've run into a variety of the 1-n selects problem described here (stack overflow). I have a Person object with a few OneToOne associations:
Person {
@Version
public Long getOptLock();
@OneToOne(fetch=FetchType.LAZY)
public PersonDetails getDetails();
@OneToOne(mappedBy = "person", fetch=FetchType.LAZY)
public LoginFailure getLoginFailure();
}
I am trying to avoid updating the optimistic lock on the Person object any time the person logs in, this would bump the opt lock, and might make it difficult to modify people in an admin GUI if they logged in during the operation.
Lazy loading for PersonDetails works fine (because the Person table has a FK into PersonDetails); the mappedBy prevents the LoginFailure from being lazy loaded, since the LoginFailure table must be checked, (and byte code instrumentation is not in use).
It seems like I have 3 options: 1) use byte code instrumentation (have not got this to work at all -- my class files don't change) 2) remove the forward relationship from Person to LoginFailure, and use a query to load this if needed. 3) implement the relationship as a OneToMany.
Do I have any other good options? Has anyone dealt with this kind of thing before?