我有以下两个对象:
@Entity
@Table(name = "B")
@NamedQueries({
@NamedQuery(name = "A.searchById", query = "SELECT myCollection FROM A WHERE id = :id"),
... })
public class B{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "B_ID")
int id;
@Column(name = "NAME")
String name;
}
@Entity
@Table(name = "A")
@NamedQueries({
@NamedQuery({several named queries...})
public class A{
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "A_ID")
int id;
@Column(name = "NAME")
String name;
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "MAPPING_B_A", joinColumns = { @JoinColumn(name = "A_ID") }, inverseJoinColumns = { @JoinColumn(name = "B_ID") })
List<B> myCollection;
}
我发出以下查询:
SELECT myCollection FROM A WHERE id = :id
Hibernate返回:未知列&#39; id&#39;在&#39; where子句&#39;
我将查询改为
SELECT myCollection FROM A as a WHERE a.id = :id
一切正常。但是第一个查询的问题是什么?好的,两个类中都有一个id列,但FROM子句中只有一个类!我还尝试在其中一个类中更改id字段的名称,但没有帮助。
答案 0 :(得分:0)