0 Replies - 588 Views - Last Post: 13 April 2017 - 06:34 AM

#1 Serg.H  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-April 17

Hibernatе query OneToMany.

Posted 13 April 2017 - 06:34 AM

I have two tables t_user and t_photo that are linked by OneToMany.
I make an id request to t_user.
In t_photo there is only one entry with this user_id.
The program returns to me several thousand records, but the record is the same.
//MY Request
Код:

@RequestMapping(value= "/api/getuser.json", method = RequestMethod.POST)
@ResponseBody
public TUserEntity GetUser(@RequestBody TUserEntity[] test){
Session session = HibernateSessionFactory.getSessionFactory().openSession();
TUserEntity user = session.load(TUserEntity.class,27);
session.close();
return user;
}
:code:

//class TUserEntity
Код:

@OneToMany(fetch = FetchType.LAZY, mappedBy = "tUserByUserId", cascade = CascadeType.ALL)
public Collection<TPhotoEntity> gettPhotosByUserId() {
return tPhotosByUserId;
}
:code:

//class TPhotoEntity
Код:

@ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
@JoinColumn(name = "user_id",insertable = false, updatable = false)
public TUserEntity gettUserByUserId() {
return tUserByUserId;
}
:code:

This post has been edited by modi123_1: 13 April 2017 - 06:37 AM
Reason for edit:: Please use the [code] button in the editor..


Is This A Good Question/Topic? 0
  • +

Page 1 of 1