zoukankan      html  css  js  c++  java
  • 一对多类中,根据多的的一方的某个属性获得一的一方的list

    一的一方: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();
  • 相关阅读:
    HDU 5698 瞬间移动
    HDU 5695 Gym Class
    HDU 5694 BD String
    HDU 5692 Snacks
    HDU 5691 Sitting in Line
    胜利大逃亡
    BFS(广度优先搜索)
    计算直线的交点数
    Division
    Jesse's Code
  • 原文地址:https://www.cnblogs.com/ms-grf/p/7678073.html
Copyright © 2011-2022 走看看