Hibernate newbie here.
So I have a User object with many Opportunity objects:
@Entity
public class User implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long userId;
private String firstName;
private String lastName;
private String email;
@OneToMany(fetch=FetchType.EAGER, cascade=CascadeType.ALL, mappedBy="user")
private List<Opportunity> opportunities = new ArrayList();
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
And I have an Opportunity object with a ManyToOne relation with a User:
@Entity
public class Opportunity implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long opportunityId;
@ManyToOne(fetch=FetchType.EAGER, cascade=CascadeType.ALL)
@JoinColumn(name="userId", nullable=false)
private User user;
private String listingUrl;
private String position;
private String organization;
private String location;
@Column(columnDefinition="text")
private String notes;
@Enumerated(EnumType.STRING)
private Action action;
@Temporal(TemporalType.TIMESTAMP)
private Date creationDate;
@Temporal(TemporalType.DATE)
private Date dueDate;
All get/set methods are emitted here just to save space. What I assumed would happen when I used the getOpportunities() method of the User class, was that it would return all the Opportunity objects in the database. I figured that the annotations would pull them automatically for me. However, it did not. So my question is, do the annotations help retrieve data from the database? How? Or are they just used for creating the database? If I want to get all the opportunities, do I have to write a custom transaction/query?