samedi 28 février 2015

Spring, Hibernate, JPA: Lazy loading id's

I'm currently in the process of converting a large project from Grails to Spring: I'm somewhat stuck when attempting to lazy-load objects id's without having to select the entire table.


The way I would like it to work, /Object/:



Object
List<child> children


to be output like so:



{children:[{id:1},{id:2}]}


So that from another controller I can then access that inner object if required using regular CRUD methods which I have implemented across all of my controllers. /child/1


With the JSON output in mind, I'm having trouble with no Session being available during serialization which is understandable, I've seen methods such as calling object.child.getId() in the service layer seems incredibly hacky to me and would also cause the entire object to be Lazily-loaded.


Overall, I'm looking to create a simple Rest Application with easy customization of the json output, something grails did with the JSON Marshalling plugin really quite well: http://ift.tt/185BLrP


Edit: I don't really wish to set eager loading, but Eager loading is a possibility. Is there a way of getting Eager Loading with a max depth?



{
children: { //depth 1
children-children: { //depth 2 (Ignore this)
}
}
}

Aucun commentaire:

Enregistrer un commentaire