Hi all,
I'm trying to build a Spring/Hibernate application on top of an existing database structure and having some problems when trying to map my Java objects to existing data using annotations. The code below is an amalgamation from a number of tutorials and general web trawling so my understand isn't as full as it should be, particularly being new to both Spring and Hibernate!
The actual problem is that when the servlet returns the JSON back to JS in my page, it seems to be creating an infinate recursion problem that manages to take down Tomcat(!!).
When I make the JS call to fetch JSON representing a Route I want to get back the Route fields along with a List/Set of which checkpoints a route uses rather than this massive recursion I'm getting.
Returned JSON:
[{"name":"External Test Patrol","duration":-2209161600000,"maxTime":-2209161000000,"minTime":-2209161600000,"oid":15138,"routePoints":[{"oid":25703,"pointNo":4,"route":{"name":"External Test Patrol","duration":-2209161600000,"maxTime":-2209161000000,"minTime":-2209161600000,"oid":15138,"routePoints":[{"oid":25703,"pointNo":4,"route":{"name":"External Test Patrol","duration":-2209161600000,"maxTime":-2209161000000,"minTime":-2209161600000,"oid":15138,"routePoints":[{"oid":25703,"pointNo":4,"route":{"name":"External Test Patrol","duration":-2209161600000,"maxTime":-2209161000000,"minTime":-2209161600000,"oid":15138,"routePoints":[{"oid":25703,"pointNo":4,"route":{"name":"External Test Patrol","duration":-2209161600000,"maxTime":-2209161000000,"minTime":-2209161600000,"oid":15138,"routePoints":[{"oid":25703,"pointNo":4,"route":{"name":"External Test Patrol","duration":-2209161600000,"maxTime":-2209161000000,"minTime":-2209161600000,"oid":15138,"routePoints":[{"oid":25703,"pointNo":4,"route":{"name":"External Test Patrol","duration":-2209161600000,"maxTime":-2209161000000,"minTime":-2209161600000,"oid":15138,"routePoints":[{"oid":25703,"pointNo":4,"route":{"name":"External Test Patrol","duration":-2209161600000,"maxTime":-2209161000000,"minTime":-2209161600000,"oid":15138,"routePoints":[{"oid":25703,"pointNo":4,"route" ............. etc etc
Both Spring and Hibernate are recent (summer 2011) versions.
The tables of interest in the DB:
ROUTES {OID, name, <other fields of no significance>}
CHECKPOINTS {OID, name, <other dull fields of no interest>}
ROUTEPOINTS {OID, route*, checkpoint*, pointno} //where route is a FK ref to ROUTES.OID and checkpoint is FK ref to CHECKPOINTS.OID
A route may have several checkpoints, a checkpoint may feature in several routes. So a manytomany relationship.
Some Java:
Route.java represents a Route object
CheckPoint.java
RoutePoint.java - the mapping table
RouteCheckPointPK.java