EclipseLink 2.0 ManyToOne not working correctly [message #636193] |
Fri, 29 October 2010 15:21 |
Edmondo Messages: 11 Registered: October 2010 |
Junior Member |
|
|
Dear all,
I am meeting a problem with EclipseLink 2.0 .
I create some entities and I persist them and they are persisted correctly. When I load them , however, a field is null. What do you suggest?
@Entity
public class Curve implements Serializable {
@Id
private String curveName;
private String description;
private static final long serialVersionUID = 1L;
@ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@JoinColumn(name = "CURRENCY_CURRENCYNAME")
private Currency currency;
@ManyToMany(mappedBy = "associatedCurves",fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<Security> securityList = new ArrayList<Security>();
@OneToMany(fetch=FetchType.EAGER)
private List<CurvePoint> curvePoints;
@Transient
private GotwareDataObject gotwareDataObject;
// Getters and setters obmitted
}
public class Currency implements Serializable {
@OneToMany(mappedBy="currency",fetch=FetchType.EAGER,cascade=CascadeType.ALL)
List<Curve> curves;
private static final long serialVersionUID = 1L;
@Id
String currencyName;
}
My problem is the following:
I create a currency Euro and a curve A.
I added a curve A to the currency Euro and I set Euro as the currency of A. This is correctly mapped in the database when I persist.
When I load with a em.find a certain currency, the List of Curve it's correctly populated. However, inside each curve, the currency is null.
What can I do?
Thank you very much
Edmondo
|
|
|
|
|
|
Re: EclipseLink 2.0 ManyToOne not working correctly [message #637183 is a reply to message #636193] |
Thu, 04 November 2010 13:53 |
|
A few issues I noticed in the code,
EoniaSwap eonia2 = new EoniaSwap();
eonia2.setName("Eonia 2 week swap");
eonia2.setDescription("Daily fixing compounded over period stipulated");
eonia2.setTicker("EUSWE2Z Curncy");
BigDecimal bigDecimal2= new BigDecimal("0.30");
****eonia1.getMarketData().setLastPrice(bigDecimal2);
>> should be eonia2
securityList.add(eonia2);
em.persist(eonia2);
EoniaSwap eonia3 = new EoniaSwap();
eonia3.setName("Eonia 3 week swap");
eonia3.setDescription("Daily fixing compounded over period stipulated");
eonia3.setTicker("EUSWE3Z Curncy");
BigDecimal bigDecimal3= new BigDecimal("0.35");
****eonia1.getMarketData().setLastPrice(bigDecimal3);
>> should be eonia2
securityList.add(eonia3);
em.persist(eonia3);
em.flush();
Curve eoniaCurve = new Curve(securityList);
eoniaCurve.setCurveName("Pippo pluto");
eoniaCurve.setCurrency(currency);
CurvePoint curvePoint1 = new CurvePoint("GOTX1234",new BigDecimal(0.73));
CurvePoint curvePoint2 = new CurvePoint("GOTX1235",new BigDecimal(0.75));
CurvePoint curvePoint3 = new CurvePoint("GOTX1236",new BigDecimal(0.77));
List<CurvePoint> curvePoints = new ArrayList<CurvePoint>();
curvePoints.add(curvePoint1);
curvePoints.add(curvePoint2);
curvePoints.add(curvePoint3);
curvePoint1.setCurve(eoniaCurve);
curvePoint2.setCurve(eoniaCurve);
curvePoint3.setCurve(eoniaCurve);
List<Curve> curves = new ArrayList<Curve>();
curves.add(eoniaCurve);
***eonia1.setAssociatedCurves(curves);
***eonia2.setAssociatedCurves(curves);
***eonia3.setAssociatedCurves(curves);
>> you cannot share the same collection with multiple different objects, each must have its own collections, i.e.
eonia3.setAssociatedCurves(new ArrayList<Curve>(curves);
If still having the issue, what is you remove the flush, or call refresh, what happens?
James : Wiki : Book : Blog : Twitter
|
|
|
Powered by
FUDForum. Page generated in 0.04205 seconds