So you have a relational database and you want to see what Addresses, Phone numbers, or Accounts are associated with a Person. By default, Java EE will only get the objects it absolutely needs; this is called lazy fetching. So solve this problem you want to fetch eagerly. In your code, find the attribute in your entity bean that you want to eagerly fetch and edit the attributes to indicate that it should eagerly fetch the information:

In the Person bean:
@OneToMany(mappedBy="person", fetch=FetchType.EAGER) private Set accounts;
Obviously there may be some changes you need to make, @OneToOne, @ManyToOne, @ManyToMany, etc. It will vary based on the circumstance.
You are spreading the wrong idea here. @Basic fields, all those primitive types for example, defaults to EAGER loading. So does relationships with a cardinality of "one-to-one" and "many-to-one". Therefore, it is only @OneToMany and @ManyToMany fields that the developer might have the need to explicitly set to use EAGER loading. Also note that FetchType.LAZY is just a hint to the provider.
Martin Andersson on 2014-07-03 18:15:49.0