1

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

smackenzie
  • 2,880
  • 7
  • 46
  • 99
  • You should post your complete enities! I remember the same strange behavior in an old project, without knowing the reason. I solved this by just changing the position of some variables in code. Think it were the OneToMany and/or JoinTable ones (list and/or sets) - I'm not sure, sry - but try yourself and pls give feedback. – zyexal Sep 14 '14 at 18:01
  • Hi, I fixed it by some random tagging of @XmlElement and moving things around. I have no idea why it now works and it didn't, but will post the working version up when I am at work tomorrow. – smackenzie Sep 14 '14 at 20:12
  • Yap, thats really strange and must be a bug somewhere. Hope someone who knows whats up, will find the question and give enlightenment :) – zyexal Sep 14 '14 at 21:30
  • Only sucked 3 days out of my life. – smackenzie Sep 14 '14 at 23:20

0 Answers0