The FetchType strategy defines strategies for fetching data from the database. The EAGER strategy is a requirement on the persistence provider runtime that data must be eagerly fetched. The  LAZY strategy is a hint to the persistence provider runtime that data should be fetched lazily when it is first accessed. 

Here is how you can specify in your annotations the fetch strategy  (fetch = FetchType.LAZY)

@Entity
@Table(name = "PET")
public class Pet implements Serializable {
	private long id;

	private Zoo zoo;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name="ZOO_ID")
	public Zoo getZoo() {
		return zoo;
	}

	public void setZoo(Zoo zoo) {
		this.zoo = zoo;
	}
}


@Entity
@Table(name = "ZOO")
public class Zoo implements Serializable {
	private long id;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID")
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
}
0
0
0
s2smodern