Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 @Consumes(JSON) annotation). Is there any conflict if this Java object is also a Hibernate entities? And is nested object working (like @ManyToOne relation)?

like image 765
Fractaliste Avatar asked Mar 29 '14 10:03

Fractaliste


1 Answers

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.

like image 75
oceansize Avatar answered Oct 26 '22 10:10

oceansize