0

My entity bean named Stock contain

@OneToMany(fetch=FetchType.LAZY,cascade=CascadeType.ALL)
@JoinColumn(name="stockid")
private List<StockSize> stockSizeList = new ArrayList<StockSize>();

My StockSize entity bean contain one field stockid from Stock

Below is the code to set Stock entity value

Stock stock = new Stock();
    stock.setDesignCode("123design");
                stock.setLotNo("123lot");
                stock.setCreatedByUserId(getIBusinessDelegateOperationSessionContext().getUserId());
                stock.setCreatedDate(new Date());
                stock.setIsSystemRecord(StaticTableConstants.NOT_ISSYSTEMRECORD);
                stock.setLastModifiedDate(new Date());
                stock.setLastModifiedByUserId(getIBusinessDelegateOperationSessionContext().getUserId());


    stock.setStockSizeList(listStockSize != null ? listStockSize : new ArrayList<StockSize>());

Its gives an error as it can't get stockid when container persist StockSize

So is there any post-persist type of thing in EJB3.0 i.e StockSize persist after persisting stock ?

or only one solution that i have to persist both entity separate.

chetan
  • 3,175
  • 20
  • 72
  • 113

1 Answers1

0

since i don't know what error you get or how your code persists i can only guess (hint *hint*)

but a common Point when dealing with Y-To-X-Relationships is that the parent (here "Stock") cant be persisted before its children (here "StockSize"). Of cause if stockSize has a x-To-Y relationship with stock than you have to persist the empty objects first and insert the relationships as and update.

If this doesn't solve your problem please post your stacktrace.

Laures
  • 5,389
  • 11
  • 50
  • 76