I am using classes which are JPA annotated to map xml data into a database and the other way around via JAXB. Problem is that objects created by JAXB do not include foreign key fields and therefore are null. This conerns ownerId in example below.
Is there a way to fix this without looping through the whole tree again and add foreign keys ?
@Entity
public class Element {
@Id
String id;
@OneToMany(mappedBy = "owner", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<Property> properties;
}
@Entity
public class Property {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int propertyId;
@ManyToOne(optional = false, cascade = CascadeType.ALL)
@PrimaryKeyJoinColumn(name = "ownerId", referencedColumnName = "id")
private Element owner;
}