Hello all,
After searching and reading so many posts here regarding the issue
of many-to-one association + lazy initialization + not-found=ignore,
I still can't understand if there is a solution for the problem.
As I see it I have only 2 options:
1) suffer from unneeded queries to be run when hitting an non existing association.
2) removing the not-found=ignore, and have a try/catch for
NotFoundObjectException surrounding my code,
when im trying to call the getter function.
If an exception is caught I set my member with a new empty instance so when the getter function will be called again, no query will be run (if the value was null, the query would run again).
Am I correct or is there a 3rd way?
My mapping
======================
Class Person {
@Id
@Column(name="P_ID")
public Long getId() {return id;}
@ManyToOne
@JoinColumn(name="NOTE_ID", insertable=false, updatable=false)
@LazyToOne(value=LazyToOneOption.NO_PROXY)
@NotFound(action=NotFoundAction.IGNORE)
public Note getNote() {return Note}
}
Class Note {
@Id
@Column(name="NOTE_ID")
public Long getId() {return id;}
}
My databse:
========
Table PERSON
-----------------
P_ID NOTE_ID
Table Note
-------------
NOTE_ID
Many thanks,
Barak
|