I am using JPA annotations and when i have relation OneToMany - ManyToOne, when i see my entity in the ManyToOne, the joinColumn is always with null value.
Next i will show my example, i have Product:
@Entity
@Table(name = "PC_PRODUCT")
public class Product extends LaunchEntity {
private static final long serialVersionUID = 1L;
@XmlElement(name = "Product_Name", required = true)
protected String productName;
@XmlElement(name = "Product_Description")
protected String productDescription;
@XmlElement(name = "Product_To_Charge")
@OneToMany(mappedBy = "product", cascade=CascadeType.MERGE)
protected List<ChargeRelation> productToCharge;
And, this is my ChargeRelation class:
@Entity
@Table(name="PC_CHARGE_RELATION")
public class ChargeRelation
extends RelationEntity
{
private static final long serialVersionUID = 1L;
@XmlElement(name = "Charge", required = true)
@OneToOne(cascade = CascadeType.MERGE)
protected Charge charge;
@XmlTransient
@ManyToOne(cascade=CascadeType.MERGE)
@JoinColumn(name="PRODUCT_ID")
protected Product product;
I am reading a xml file, convert data for a string, make unmarshall for my root object and persist this object.
The problem is when i found a charge relation in my string, the values are inserted on the charge relation table but the column with the product_id is always null.
I have all setters and getters defined. How i can force this to make the manual insert? thanks