one-to-many 从one到many查询?

one-to-many 从one到many查询?

many的一方有one的一方的id,先要通过这个id查询从所有的one
实体类:
@Entity(name="SP_UNIT_TYPE")
public class SpUnitType implements Serializable{
 private static final long serialVersionUID = 1L;
 private Integer id;
 private String code;
 private String nameEnglish;
 private String nameChinese;
 private ValidState validState = ValidState.DISABLE;
 private Flag flag = Flag.YES;
 private String creator;
 private Date createDate = new Date();
 private String modifier;
 private Date modifyDate = new Date();
 private String shortName;
 
 private Set<SpUnit> spUnits = new HashSet<SpUnit>();

@OneToMany(mappedBy="spUnitType",cascade=CascadeType.ALL,fetch=FetchType.EAGER)
 public Set<SpUnit> getSpUnits() {
  return spUnits;
 }

 public void setSpUnits(Set<SpUnit> spUnits) {
  this.spUnits = spUnits;
 }


.....省略
@Entity(name="SP_UNIT")
public class SpUnit implements Serializable{
 private static final long serialVersionUID = 1L;
 private Integer id;
 private String code;
 private String nameEnglish;
 private String nameChinese;
 private ValidState validState = ValidState.DISABLE;
 private Flag flag = Flag.YES;
 private String creator;
 private Date createDate = new Date();
 private String modifier;
 private Date modifyDate;
 private String shortName;
 
 private SpUnitType spUnitType;
@ManyToOne(cascade=CascadeType.REFRESH,optional=false)
 @JoinColumn(name="SP_UNIT_TYPE_ID")
 public SpUnitType getSpUnitType() {
  return spUnitType;
 }
 public void setSpUnitType(SpUnitType spUnitType) {
  this.spUnitType = spUnitType;
 }
........省略
——————————————————————————————
想通过SpUnitType的id查询出SpUnit的所有对象。
这个用JPQL怎么做呀?请高手指点。

你可能感兴趣的:(one-to-many 从one到many查询?)