facebook

scaffolding restful service response with duplicate output

  1. MyEclipse IDE
  2.  > 
  3. Spring Development
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #345473 Reply

    atl_ala
    Member

    I have tried to scaffolding a crud web project for rest/json support with the default derby database (choosed hibernate 4).

    However, it kept producing duplicate output, i.e.,

    http://localhost:8080/sp/Office/2

    I got tons of same outputs (see attachment). Also the console is full of these kind of errors:
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:268)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:160)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:131)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:363)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:314)

    I have searched around and people are talking about lazy loading problem for hibernate, ” your transaction will end, the Hibernate Session gets closed and when the mapper tries to access that collection”

    I mean since it is a out of box function, do we have some kind of workaround to address the issue quickly?

    Attachments:
    You must be logged in to view attached files.
    #345480 Reply

    atl_ala,

    Sorry that you are seeing this issue.

    > Can you please be more clear on the issue ? Can you please mention the exact steps in detail (right from creating a project), to help us replicate the issue at our end ?

    > Please share your MyEclipse installation details from MyEclipse > Installation summary > Installation details ?

    > Can you also check the .log file which is located at <workspace dir>/.metadata/.log for any errors of interest ? If yes then paste the errors here for us to investigate further.

    #345489 Reply

    atl_ala
    Member

    1. Followed this video:

    Around 7:29, I have checked Web Service and Json option.

    2. Version 10.6
    Build id: 10.6-20120727

    3. .log has nothing appended when this issue happened. Console is full of repeated message as following:

    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:268)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:160)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:131)
    at org.codehaus.jackson.map.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:268)
    at org.codehaus.jackson.map.ser.BeanSerializer.serializeFields(BeanSerializer.java:160)
    at org.codehaus.jackson.map.ser.BeanSerializer.serialize(BeanSerializer.java:131)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:363)
    at org.codehaus.jackson.map.ser.ContainerSerializers$CollectionSerializer.serializeContents(ContainerSerializers.java:314)

    #345502 Reply

    atl_ala,

    Thanks for the details provided.

    We couldn’t replicate the issue at our end after following the video. It is not clear how you added Hibernate 4 support while Scaffolding the web project. Can you please explain how you have added Hibernate 4 support while scaffolding ?

    Also, can you please clarify which version of Spring libraries did you select during scaffolding ? Is it Spring 2.5 / 3.0 / 3.1 ?

    If possible, can you please attach the sample project which exhibits this issue to help us investigate further ?

    #345884 Reply

    atl_ala
    Member

    I did some more testing and here is what I have found:

    office and employee was linked with a officeCode foreign key. then REST try to display like

    office (
    ….
    employees (
    ….
    office ()
    )

    )

    Endless looping.

    How can we fix it? I.e., control it to display only 1 level then stop? I guess the CRUD rest code should provide options for this.

    Same thing for create a office with employee together. Due to the foreign key, how can you present with json to assign an employee belongs to which office even the office has not been created yet? The CRUD sample did not cover that too.

    #345886 Reply

    atl_ala
    Member

    loop display screenshot

    Attachments:
    You must be logged in to view attached files.
    #345908 Reply

    atl_ala,

    We couldn’t replicate the issue at our end after linking office and employee tables with a officeCode foreign key.

    Can you please attach the sample project which exhibits this issue to help us investigate further ? Also, please paste the schema of the tables on which you are trying to scaffold ?

    #345936 Reply

    atl_ala
    Member

    source code attached.

    Attachments:
    You must be logged in to view attached files.
    #345957 Reply

    atl_ala,

    Thanks for the source code provided.

    We could replicate the issue at our end with your source code. Inorder to fix the issue, you need to add @JsonIgnore annotation above getOffice method (in Employee.java file) and getEmployees method (in Office.java file).

    Let us know how it works for you.

    #346186 Reply

    atl_ala
    Member

    sorry it took long to response.

    #346217 Reply

    atl_ala,

    Glad that the duplicate output issue is solved. The tutorials are just to help you get started. we can’t usually provide much assistance with that and you will usually need to post on more appropriate development forums (for example, http://www.stackoverflow.com ) for better support on this.

    Do let us know if you see any issues in MyEclipse.

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: scaffolding restful service response with duplicate output

You must be logged in to post in the forum log in