My Spring Data Warehouses are stored as the default @RepositoryRestResource without any configuration.
JPA Essence:
@Entity
@Table(name = "flat")
public class Flat implements Serializable {
private static final long serialVersionUID = -7402659216552976109L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "flat_id")
private Integer id ;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "house_id", referencedColumnName="house_id", insertable=false, updatable=false)
private House house;
@Column(name = "kad_num")
private String kadNum;
.....
I want the obkect object to be returned in JSON as an inline part of the Flat object, but only get the URL of the house
/ repository / apartments / 442991:
{
"kadNum" : "78:06:0002202:8981",
"sqrFull" : 52.7000,
"flatNum" : "311",
"_links" : {
"self" : {
"href" : "http://localhost:8080/kap/repository/flats/442991"
},
"house" : {
"href" : "http://localhost:8080/kap/repository/flats/442991/house"
}
}
}
At the same time, OneToMany User-Role relationships are selected with the role name:
@Entity
@Table(name = "\"user\"")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "user_id")
private Integer id;
private String login;
private String email;
private String password;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "user_id", nullable=false , updatable = false, insertable = true)
private Set<Role> roles = new HashSet<Role>();
.....
request: / repository / users / 5
{
"id" : 5,
"login" : "op898",
"email" : "op20140603@gmail.com",
"password" : "c6172176f8f5d7e660eb4dcfad07a6ca",
"roles" : [ {
"roleName" : "OPERATOR"
} ],
"_links" : {
"self" : {
"href" : "http://localhost:8080/kap/repository/users/5"
}
}
}
I can not understand the difference, except for the type of relationship. Any ideas? Thanks you