First, appologies for the long post, I have tried to cut it down as much as possible.
I am trying to persist an object using JPA. While most of the objects fields are persisted fine, one is skipped completely, yet no errors are throw.
In short, I am trying to persist an instance of ListedItemDetail. Unfortuanately, the BidCollection field is being totally ignored, and there is no trace of it in the database. I have no idea why..
I have included the relavent source. The source was generated from 3rd party schema. I am using orm.xml for the JPA mapping, and have included the reavent bits below too.
public class ListedItemDetail extends Item implements Serializable{
protected BidCollection bids;
}
public class Item extends ExtensibleDataObject implements Serializable {
protected int listingId;
}
public class BidCollection extends PagedCollectionOfBidte0R55Be implements
Serializable{
private final static long serialVersionUID = 1L;
}
public class PagedCollectionOfBidte0R55Be implements Serializable {
private final static long serialVersionUID = 1L;
protected Integer totalCount;
protected Integer page;
protected Integer pageSize;
protected InnerCollectionOfBidte0R55Be list;
}
public class InnerCollectionOfBidte0R55Be implements Serializable {
private final static long serialVersionUID = 1L;
protected List<Bid> bid;
}
public class Bid extends ExtensibleDataObject implements Serializable {
private final static long serialVersionUID = 1L;
protected String account;
protected Boolean isByMobile;
protected Boolean isByProxy;
protected Timestamp bidDate;
protected Boolean isBuyNow;
protected Member bidder;
}
orm.xml:
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.0">
<entity class="nz.co.trademe.api.v1.ListedItemDetail">
<attributes>
<cascade>
<cascade-persist/>
</cascade>
<embedded name="bids">
</embedded>
</attributes>
</entity>
<entity class="nz.co.trademe.api.v1.Item">
<inheritance strategy="JOINED"/>
<discriminator-column discriminator-type="STRING"/>
<attributes>
<id name="listingId">
</id>
</attributes>
</entity>
<embeddable class="nz.co.trademe.api.v1.PagedCollectionOfBidte0R55Be">
</embeddable>
<embeddable class="nz.co.trademe.api.v1.InnerCollectionOfBidte0R55Be">
<attributes>
<element-collection name="bid">
</element-collection>
</attributes>
</embeddable>
<embeddable class="nz.co.trademe.api.v1.Bid">
</embeddable>
<embeddable class="nz.co.trademe.api.v1.BidCollection">
</embeddable>
</entity-mappings>
The issue is related to BidCollection being embeddable and using inheritance. JPA does not support inheritance with embeddables.
Technically EclipseLink does support inheritance with embeddables, but not currently through JPA annotations.
You could either remove the inheritance, or try setting up the inheritance using a DescriptorCustomizer.
Your model also seems very convoluted, you might want to rethink it.