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 @Consumes(JSON)
annotation). Is there any conflict if this Java object is also a Hibernate entities? And is nested object working (like @ManyToOne
relation)?
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 @ManyToOne
making 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With