- This topic has 10 replies, 2 voices, and was last updated 11 years, 1 month ago by
support-pradeep.
-
AuthorPosts
-
atl_alaMemberI 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.
support-pradeepMemberatl_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.
atl_alaMember1. Followed this video:
Around 7:29, I have checked Web Service and Json option.
2. Version 10.6
Build id: 10.6-201207273. .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)
support-pradeepMemberatl_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 ?
atl_alaMemberI 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.
support-pradeepMemberatl_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 ?
support-pradeepMemberatl_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.
atl_alaMembersorry it took long to response.
support-pradeepMemberatl_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.
-
AuthorPosts