andrevcf wrote:
I think it means that, when I put the optional=false, Hibernate will use lazy.
But, even when I put optional=false
@OneToOne(fetch=FetchType.LAZY, optional=false,mappedBy="pessoa")
the TbUsuario IS queried...
what to do then?
http://java.sun.com/javaee/5/docs/api/j ... #optional()
Whether the association is optional. If set to false then a non-null relationship must always exist.
When you use the option (optional = false), means the items is required mandatory by the object, you have to use (optional = true).
The document link mentioned previously says, you cannot have LazyLoading for a one-to-one, as the object WILL BE required by Hibernate,
Quote:
But now imagine your B object may or may not have associated C (constrained="false"). What should getCee() return when specific B does not have C? Null. But remember, Hibernate must set correct value of "cee" at the moment it set B (because it does no know when someone will call getCee()). Proxy does not help here because proxy itself in already non-null object.
Also why do u want to lazy load it? Is it a blob that u cannot afford to eager load?