I have cyclic issues with a 2 way JPA relationship using Jersey. I am trying to solve the cyclic dependency with @XmlElement and @XmlInverseReference, and while getting closer - my json wont parse as it seems to be introducing an invalid "close bracket".
My entities look as below:
@Entity(name = "PR_GPT")
@Table
@XmlRootElement
@PersistenceUnit(unitName = "graps-jpa")
public class PrGPT {
@ManyToOne(optional=false)
@JoinColumn(name="THERAPY_AREA")
@XmlInverseReference(mappedBy="gpts")
@XmlElement
protected PrTherapyArea therapyArea;
@Entity(name = "PR_THERAPY_AREA")
@Table
@XmlRootElement
@PersistenceUnit(unitName = "graps-jpa")
public class PrTherapyArea {
@OneToMany(mappedBy="therapyArea", orphanRemoval = true, cascade = { javax.persistence.CascadeType.PERSIST, javax.persistence.CascadeType.MERGE }, fetch = FetchType.EAGER)
protected List<PrGPT> gpts;
And my json output which is failing to be parsed on the client is as below:
[{"therapyArea":{"id":[1},"gptDesc":"GPT 12345678912132ddd","id":1},{"therapyArea":{"id":[4},"gptDesc":"GPT 291","id":2}]
You can see here:
"therapyArea":{"id":[1}
There is a rogue "[" in front of the therapy area ID....
I am using EclipseLink.
Update: Error is:
SyntaxError: Unexpected token }
at Object.parse (native)
at fromJson (http://mydomain:8080/misf-web/lib/angular/angular.js:1139:14)
at $HttpProvider.defaults.defaults.transformResponse (http://mydomain:8080/misf-web/lib/angular/angular.js:7481:18)
at http://mydomain:8080/misf-web/lib/angular/angular.js:7429:12
at forEach (http://mydomain:8080/misf-web/lib/angular/angular.js:325:18)
at transformData (http://mydomain:8080/misf-web/lib/angular/angular.js:7428:3)
at transformResponse (http://mydomain:8080/misf-web/lib/angular/angular.js:8122:17)
at wrappedCallback (http://mydomain:8080/misf-web/lib/angular/angular.js:11561:81)
at http://mydomain:8080/misf-web/lib/angular/angular.js:11647:26
at Scope.$eval (http://mydomain:8080/misf-web/lib/angular/angular.js:12673:28)
UPDATE:
XML representation is fine, only breaks for JSON...is this a bug?
JSON:
[{"id":1,"gptDesc":"GPT 12345678912132ddd","therapyArea":{"id":[1,"Oncology"}},{"id":2,"gptDesc":"GPT 291","therapyArea":{"id":[4,"RI"}}]
XML
<prGPTs>
<prGPT>
<id>1</id>
<gptDesc>GPT 12345678912132ddd</gptDesc>
<therapyArea>
<id>1</id>
<therapyArea>Oncology</therapyArea>
</therapyArea>
</prGPT>
<prGPT>
<id>2</id>
<gptDesc>GPT 291</gptDesc>
<therapyArea>
<id>4</id>
<therapyArea>RI</therapyArea>
</therapyArea>
</prGPT>
</prGPTs>
Regards
i