我有两张桌子:
A(bigint id, ...)
B(bigint id, varchar name, bigint id_A)
现在我想从A中获取所有存在于B中的行(并且B中的那些行具有名称,例如Andy)
Plase帮助我创建动态查询
A级
@Entity
@Table(name = "A", schema = "mySchema")
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public class A{
@Id
private Long id;
}
B级
@Entity
@Table(name = "B",
schema = "mySchema",
uniqueConstraints = { @UniqueConstraint(columnNames = {
"some_id", "id_A" }) })
public class B{
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "Seq")
@SequenceGenerator(name = "Seq", sequenceName = "mySchema.mySeq")
private Long id;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_A", nullable = false)
private A a;
@Column(name = "id_A", updatable = false, insertable = false)
private Long IdA;
}
答案 0 :(得分:0)
有几个奇怪的部分。例如这样:
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_A", nullable = false)
private A a;
@Column(name = "id_A", updatable = false, insertable = false)
private Long IdA;
使用@JoinColumn
注释,您告诉JPA提供程序它应该使用指定的列进行内部映射,但是使用IdA字段,您将尝试自己管理该列。它会是什么?