Hi,
I'm new to JPA and now stuck with a problem!
I have two tables Person and PersonAddress.
In the Person entity, I have
@OneToMany(mappedBy="personid")
private Set<Personaddress> personaddressCollection;
and
public Set<Personaddress> getPersonaddressCollection() {
return this.personaddressCollection;
}
public void setPersonaddressCollection(Set<Personaddress> personaddressCollection) {
this.personaddressCollection = personaddressCollection;
}
In the PersonAddress entity, I have
@ManyToOne
@JoinColumn(name="PERSONID")
private Person personid;
I'm doing a query similar to one below:
List<Person> personlist = em.createQuery("SELECT e FROM Person e").getResultList();
I am expecting it to return all the data from Person table along with the data in PersonAddress table in the Set available in Person entity. The size of personlist is correct, but when I try to read the PersonAddress collection, I'm getting null values. But the database has values in it and it cannot be null.
Corresponding to every Partner, there will be a PartnerAddress which will not be null. How do I query it with JPA if whatever I have done so far is wrong?
Please help.