I was hoping that someone could shed light on this for me. I do not quite understand what is happening with this error. I have an object that I use to create multiple records in a database. I get an illegalStateException when a transaction completes and synchronization is in progress. all this is in the process of populating db from a web service providing all the data. Right now I have data processed in such a way as not to cause foreign key constraint errors, but relationships with entities stop me.
Caused by: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: entities.cmic.ajrs.com.Categories[pkId=null].
The entity I'm trying to save is called ProductBase. ProductBase has a foreign key called pkBrand in the Brand_Data table with the corresponding BrandData entity.
I can set CascadeType for EVERYTHING for this relationship, but I really don't want to create this entity at this time.
Here are the entities (minus some getters and setters)
@Entity @Table(name = "product_base") @NamedQueries({ @NamedQuery(name = "ProductBase.findAll", query = "SELECT p FROM ProductBase p"), @NamedQuery(name = "ProductBase.findByPkId", query = "SELECT p FROM ProductBase p WHERE p.pkId = :pkId"), @NamedQuery(name = "ProductBase.findByColorsAvail", query = "SELECT p FROM ProductBase p WHERE p.colorsAvail = :colorsAvail"), @NamedQuery(name = "ProductBase.findBySeriesName", query = "SELECT p FROM ProductBase p WHERE p.seriesName = :seriesName"), @NamedQuery(name = "ProductBase.findByStatusCodes", query = "SELECT p FROM ProductBase p WHERE p.statusCodes = :statusCodes"), @NamedQuery(name = "ProductBase.findByTs", query = "SELECT p FROM ProductBase p WHERE p.ts = :ts")}) public class ProductBase implements Serializable { private static final long serialVersionUID = 1L; @Id @Basic(optional = false) @Column(name = "pk_id") private Integer pkId; @Column(name = "colors_avail") private String colorsAvail; @Column(name = "series_name") private String seriesName; @Column(name = "status_codes") private String statusCodes; @Basic(optional = false) @Column(name = "ts") @Temporal(TemporalType.TIMESTAMP) private Date ts; @OneToMany(mappedBy = "productBase", fetch = FetchType.LAZY) private Collection<ProductSorts> productSortsCollection; @OneToOne(cascade = CascadeType.ALL, mappedBy = "productBase", fetch = FetchType.LAZY) private MapTarget mapTarget; @OneToOne(cascade = CascadeType.ALL, mappedBy = "productBase", fetch = FetchType.LAZY) private KeyFeatures keyFeatures; @JoinColumn(name = "pk_category", referencedColumnName = "pk_id") @ManyToOne(optional = false, fetch = FetchType.LAZY) private Categories categories; @JoinColumn(name = "pk_brand", referencedColumnName = "pk_id") @ManyToOne(optional = false, fetch = FetchType.LAZY) private BrandData brandData; @OneToMany(mappedBy = "productBase", fetch = FetchType.LAZY) private Collection<PromotionsByModel> promotionsByModelCollection; @OneToMany(mappedBy = "productBase", fetch = FetchType.LAZY) private Collection<ProductEnhancedFeatures> productEnhancementFeaturesCollection; @OneToMany(mappedBy = "productBase", fetch = FetchType.LAZY) private Collection<SkuBasic> skuBasicCollection; @OneToMany(mappedBy = "productBase", fetch = FetchType.LAZY) private Collection<ProductMeasurements> productMeasurementsCollection; public ProductBase() { } @Entity @Table(name = "brand_data") @NamedQueries({ @NamedQuery(name = "BrandData.findAll", query = "SELECT b FROM BrandData b"), @NamedQuery(name = "BrandData.findByPkId", query = "SELECT b FROM BrandData b WHERE b.pkId = :pkId"), @NamedQuery(name = "BrandData.findByCommonBrandId", query = "SELECT b FROM BrandData b WHERE b.commonBrandId = :commonBrandId"), @NamedQuery(name = "BrandData.findByCommonBrandName", query = "SELECT b FROM BrandData b WHERE b.commonBrandName = :commonBrandName"), @NamedQuery(name = "BrandData.findByTs", query = "SELECT b FROM BrandData b WHERE b.ts = :ts")}) public class BrandData implements Serializable { private static final long serialVersionUID = 1L; @Id @Basic(optional = false) @Column(name = "pk_id") private Integer pkId; @Column(name = "common_brand_id") private String commonBrandId; @Column(name = "common_brand_name") private String commonBrandName; @Basic(optional = false) @Column(name = "ts") @Temporal(TemporalType.TIMESTAMP) private Date ts; @OneToMany(cascade = CascadeType.ALL, mappedBy = "brandData", fetch = FetchType.LAZY) private Collection<ProductBase> productBaseCollection; public BrandData() { }