Using Spring, 3.2.7, Hibernate 4.2.12, Jackson 2.3.3 And experimenting with references in jackson using JsonIdentityInfo.
I have an entity taxanomy, with a parent and children, both references to Taxanomy self.
@Entity
@Table(name="taxanomy")
@JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id")
public class Taxanomy implements Serializable {
...
The parent:
@ManyToOne(fetch=FetchType.EAGER)
@Cascade({org.hibernate.annotations.CascadeType.ALL})
@JoinColumn(name="parent_id", nullable=true)
public Taxanomy getParent() {
...
The children:
@OneToMany(mappedBy="parent", fetch=FetchType.EAGER)
@Cascade({org.hibernate.annotations.CascadeType.ALL})
public Set<Taxanomy> getChildren() {
I retrieve all Taxanomy objects, with a findAll method. This returns all object trees. The root objects contain via the children relation all other taxanomy objects. I want all objects in a list, but on the client side the returned list contains 2 root objects and for the rest numbers (ids).
taxanomy = [];
function getTaxanomy() {
$.ajax({ url: 'taxanomy/all'
, dataType : 'json'}).done(function(data) {
taxanomy = data;
});
}
>> taxanomy
>> [>Object, 1001, >Object, 1005, 1005, 1003, 1007, 1006, 1002]
^ ^ ^ ^ ^ ^ ^
|______________|_____|_____|_____|_____|_____|_ want real objects?
How can I on the client side force the generation of all objects and not the ID references? I know I can iterate (or recurse) the trees and map the objects with the ids
Try the annotation: