简体   繁体   中英

Java Persistence Query Language JOIN

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. eg 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM