再次使用JPA没有意义
时间:2020-03-06 15:05:05 来源:igfitidea点击:
我早些时候问过这个问题,并被告知要查看映射依据。
I have 2 tables: A s_id(key) name cli type
B sa_id(key) s_id user pwd.
So in Jpa I have:
@Entity class A...{
@OneToMany(fetch=FetchType.EAGER)
@JoinTable( name="A_B",
joinColumns={@JoinColumn(name="a_id",
table="a",unique=false)},
inverseJoinColumns={@JoinColumn(name="b_id",
table="b", unique=true)} ) Collection
getB(){...} }
class b is just a basic entity class
with no reference to A.
Hopefully that is clear. My question
is: Do I really need a join table to
do such a simple join? Can't this be
done with a simple joincolumn or
something?
因此,现在如果有,但是jpa尝试使用一些不存在的新列(s_s_id)来编写查询
@Entity
class A{
...
@OneToMany(fetch=FetchType.EAGER, mappedBy="s")
Collection<B> x;
}
@Entity
class B{
@ManyToOne
A s;
}
With these tables:
A
s_id(key) name cli type
B
sa_id(key) s_id(the keys from A) user pwd.
我该如何执行OneToMany和ManyToOne的联接,这样就不需要新的列或者新的表?请给我一个例子。问题是在B表中缺少外键吗?
如果我遗漏了映射,则会在"字段列表"中得到"未知列't1.S_S_ID"。
如果我输入的是"字段列表"中的"未知列'S_S_ID'",
解决方案
我找到了它,我需要添加@ JoinColumn并给它起个名字...

