There is a table

___User______ ____Group_____ user_id ------------| data_id_grou name |_________id_user_id password name 

GroupEntity.java

 ... @ManyToOne @JoinColumn(name = "user_id_user") public User getUser() { return user; } public void setUser(User user) { this.user = user; } ... 

UserEntity.java

 ... private long id_album; ... @Id @GeneratedValue @Column(name = "id_user") protected long getId_user() { return id_user; } ... 

I need to get a list of milestones in which there is a defined User. in DAO search, creation, etc. everything is done perfectly. But such a sample in hibernate I do not know how to do

  • It looks like JPA, for example, then em.createQuery("SELECT g FROM GroupEntity g WHERE g.user = :user").setParameter("user", user).getResultList(); where em is your EntityManager, user is user - Sergey
  • Similarly, in your groups, only one user? - Sergey
  • Add information about what you are using for DAO and you will definitely be helped. Most likely, this can either be solved by a slightly fanciful Criteria, or by using a single HQL query. - Victor

1 answer 1

If your DAO is built on Criteria , then you need to look towards the Subqueries and DetachedCriteria .