Fractaliste Fractaliste - 1 month ago 10x
Java Question

Mapping Json object to Hibernate entity

I'm going to start a project of a REST application managed with Spring and with Hibernate for my model.

I know that Spring allows you to get Java object from the HTTP Request (with

annotation). Is there any conflict if this Java object is also a Hibernate entities? And is nested object working (like


We were using such approach to simplify design and get rid of many dtos (we were abusing them too much). Basically, it worked for us.

However, in our REST model we were trying to do not expose other relations for an object as you can always create another REST resources to access them.

So we just put @JsonIgnore annotations to relations mappings like @OneToMany or @ManyToOnemaking them transient.

Another problem I see that if you still like to return these relations you would have to use Join.FETCH strategy for them or move transaction management higher so that transaction still exists when a response is serialized to JSON (Open Session In View Pattern). On my opinion these two solutions are not so good.