码迷,mamicode.com
首页 > 其他好文 > 详细

一对多类中,根据多的的一方的某个属性获得一的一方的list

时间:2017-10-16 19:25:28      阅读:131      评论:0      收藏:0      [点我收藏+]

标签:import   ota   ble   ber   问题   size   ffd   query   根据   

一的一方:AppVsStaff.java

AppVsStaff中包含两个多的一方,Applications.java和StaffDict.java

import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
@Table(name = "APP_VS_STAFF")
public class AppVsStaff {
  @Id
  @Column(name="APP_VS_EMP_ID")
  @NotNull(message = "应用程序人员关系ID不能为空")
  @Size(min = 1,max = 20,message = "应用程序人员关系ID不能超过20字且不能为空")
  private String  AppVsEmpId;

  @JoinColumn(name = "APP_ID")
  @ManyToOne
  @NotFound(action = NotFoundAction.IGNORE)
  private Applications applications;

  @JoinColumn(name = "EMP_ID")
  @ManyToOne
  @NotFound(action = NotFoundAction.IGNORE)
  private StaffDict staffDict;

  @Column(name="CAPABILITY")
  private String capability;
}

问题:要根据StaffDict中的某个属性查出Applications对应的list

解决如下:

List<Applications> appList = new ArrayList<>();
String jpql = "SELECT app FROM AppVsStaff appVsStaff LEFT JOIN appVsStaff.applications app WHERE appVsStaff.staffDict.userName=:userName";
appList = entityManager.createQuery(jpql).setParameter("userName", userName).getResultList();

 

一对多类中,根据多的的一方的某个属性获得一的一方的list

标签:import   ota   ble   ber   问题   size   ffd   query   根据   

原文地址:http://www.cnblogs.com/ms-grf/p/7678073.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!