I\'m using Spring(xml+annotations), Hibernate(annotations) in this web service project. The database relationship diagram, models, expected and actual output are given below
Here is a bit lengthy approach. But needs some design modifications in your app. I had a similar problem and I created separate pojos for every entity classes.
In service layer I use these pojos instead of the entity objects as parameters and I use appropriate getters/setters to set/get the properties to/from entity classes. In this way you can get/set the properties you want to and avoid unwanted ones. However I implemented additional methods in DAO layer to get the related entities. This is very lengthy approach but solved the problem for me.
This seems pretty old but let me put my coins here as well; I would seperate the entity and model. Means;
> Client <-> Application : Models
>
> Application <-> Database : Entities
And your service layer or whatever layer you process data should make the conversion between entities and models.
Because you are using the @JsonBackReference on the Customer property in the Loan entity, the Customer object will not included in the serialization. Use the @JsonManagedReference for the Customer in the Loan object and use @JsonBackReference on the Loan property in the Customer entity.
This will serialize the Customer property of your Loan entity. But the Customer object serialization will not contains the Loan property. You need to pick one side of the relationship to serialize.
To allow both side, use @JsonIdentityInfo annotation in your entity and remove the @JsonBackReference and @JsonManagedReference. You entities will be something like:
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "customerId")
public class Customer implements Serializable {
...
}
The property of the @JsonIdentityInfo refer to your entity id property, for Customer this will be customerId. Do this for Loan and Item also.