我有一门语言和一个国家级课程。
@Entity
@Table(name = "countries")
@org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
@NamedQueries({
@NamedQuery(name="Country.findLanguagesByCountryId",query="???")
})
public class Country implements IEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false, unique = true)
private String name;
@ManyToMany(targetEntity = Language.class)
@JoinTable(name = "country_language", joinColumns = {@JoinColumn(name = "cid")}, inverseJoinColumns = {@JoinColumn(name = "lid")})
private Set<Language> languages;
}
@Entity
@Table(name = "languages")
public class Language implements IEntity {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(nullable = false, unique = true)
private String name;
}
如您所见,国家/地区有语言列表,但语言没有国家/地区列表。
我需要HQL,它应该按国家/地区ID查找语言。
答案 0 :(得分:0)
我想我已经找到了答案
select language from Country country
inner join country.languages language
where country.id=?1