I have two tables :
A(bigint id, ...)
B(bigint id, varchar name, bigint id_A)
and now I want get all rows from A which exists in B (and those rows in B have name eg Andy)
Plase help me create dynamic query
class A
@Entity
@Table(name = "A", schema = "mySchema")
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
public class A{
开发者_如何学运维 @Id
private Long id;
}
class 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;
}
There are several weird parts. e.g. this:
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "id_A", nullable = false)
private A a;
@Column(name = "id_A", updatable = false, insertable = false)
private Long IdA;
With the @JoinColumn
annotation you are telling the JPA provider that it should use the specified column for internal mapping, but with the IdA field, you are trying to manage the column yourself. Which is it going to be?
精彩评论