Here's a little tutorial on mapping one-to-one associations using JPA with Hibernate as the persistence framework.
http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=17mappingonetooneassociations
I think what you want is a lazy attribute, as opposed to a full annotation:
Code:
@OneToOne(cascade=CascadeType.ALL,
fetch=FetchType.LAZY)
@JoinColumn(name="detail_id")
public ExamDetail getDetail() {
return detail;
}
The FetchType.LAZY will stop the eager loading of associated objects. With onetoone relationships, the default is eager.
Quote:
For performance reasons, it's always preferential to minimize the load placed on a system's memory. As such, most associations are set to a FetchType of LAZY. This is especially true for one to many and many to many relationships, where the impact of loading a large number of associated properties can be significant.
For one-to-many and many-to-many relationships, the default FetchType is LAZY. However, for one-to-one mappings, the default is EAGER, meaning that a class, and all of its one-to-one associations, are loaded into memory when it is invoked by the client. If this is not the behavior you want, you can set the FetchType to LAZY in your @OneToOne annotations.
http://www.thebookonhibernate.com/Javac ... sociations