0

I am modelling, in a JPA framework, the situation of a user selling multiple articles to other users. I have three entities: User, Article and Order. They have the following relationships:

  • User has @OneToMany relationships with Order and Article, annotated @XmlTransient.

  • Article has a @ManyToOne relationship with User

  • Order has @ManyToOne relationships with User and Article

Everything works right and I can succesfully persist these entities in my database. The problem is when I want to retrieve them from the server. The server sends me without problems objects of type User and Article, however it fails with an "Internal Server Error" when trying to send an object of type Order (which is completely well formed before being sent).

I'm using GlassFish 4, implementing REST web services with JAX. There is no logging for these errors so I don't know where to start to look for a solution! I guess it might be a history of circular relations but I don't really see how it can be fixed.

Thanks for your help!

splinter123
  • 1,183
  • 1
  • 14
  • 34
  • The easiest way to troubleshoot this is to implement an `ExceptionMapper` that will handle all exceptions, and log them for you. Then using the logs you can troubleshoot why this is occurring. – John Ament Jul 15 '14 at 10:56
  • 1
    thanks, but I don't think this will help in my case. There are no exceptions inside my REST methods, everything works well up to the "return" statement (I checked this by logging intermediate values). The problem happens somewhere after, in the translation to JSON. That's why I was more interested in the consistency of the relationship structure of my entities. – splinter123 Jul 15 '14 at 12:06
  • Right, that's why I was saying to add an exception mapper. There is an exception that's causing the 500 error. I'm guessing it's a lazy initialization exception. Glassfish probably doesn't print this by default, but if you had an exception mapper you could print it yourself. – John Ament Jul 15 '14 at 16:05
  • I did it, using [this](https://community.jboss.org/wiki/RESTEasyExceptionHandlingWithExceptionMapper?_sscc=t) implementation, but still 500 Error with no additional info... – splinter123 Jul 15 '14 at 18:32
  • See [my answer](http://stackoverflow.com/a/40897559/1751640) – Mordechai Nov 30 '16 at 20:28

0 Answers0