jaxb - Memory error with Jersey Jax-RS -
i returning large amount of data via rest service. query returns 200,000 rows of data gets converted xml. when run service in ie8 error "there not enough storage complete operation".
is there best practice returning large amout of data way?
the database run query in 5 seconds, i'm guessing problem jaxb converting xml.
does have ideas improve this?
the problem
i'm assuming using jpa data objects can handled jaxb. if case jpa objects may using lazy loading meaning query may not realize data @ once. jaxb implementation traverses object graph, more , more of brought memory until run out.
option #1 - provide data in chunks
one approach return data in chunks , offer uri 1 below:
these parameters tie in nicely jpa query settings:
namedquery.setfirstresult(10); namedquery.setmaxresults(100); option #2 - provide links more data
alternatively, instead of including data can provide links more. example instead of:
<purchase-order> <product id="1"> <name>...</name> <price>...</price> ... </product> <product id="2"> <name>...</name> <price>...</price> ... </product> ... </purchase-order> you return following, client can request details on products using provided uri. can map in jaxb using xmladapter.
<purchase-order> <product>http://www.example.com/products/1</product> <product>http://www.example.com/products/2</product> ... </purchase-order> for more information on xmladapter see:
Comments
Post a Comment