저는 JOOQ를 처음 사용할 때 문제가 있습니다. 그러나 해결책을 찾을 수 없습니다.JOOQ 다른 POJO와 POJO 객체 가져 오기 - 테이블의 외래 키
CREATE TABLE Sellers
(
id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(255) NOT NULL,
);
CREATE TABLE Clients
(
id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
name varchar(255) NOT NULL,
seller_id int,
FOREIGN KEY (seller_id) REFERENCES Sellers(id)
);
Client
이 foreign key
이 있고 그에게 할당 된 Seller
정의 - 아래 SQL Sellers
및 Clients
: 나는이 개 테이블 간단한 데이터베이스가 있습니다.
나는 클라이언트에서 JOOQ를 사용하여 클라이언트를 얻고 싶지만 join()
을 사용하면 각 클라이언트에 Seller
개체를 얻습니다. 가능한가? 그렇다면 그렇게하는 방법? 내 JOOQ 코드가 클라이언트를 얻을 수있어 여기
public class Seller {
private final SimpleIntegerProperty id = new SimpleIntegerProperty();
private final SimpleStringProperty name = new SimpleStringProperty();
...
//setters and getters here
...
}
public class Client {
private final SimpleIntegerProperty id = new SimpleIntegerProperty();
private final SimpleStringProperty name = new SimpleStringProperty();
private final SimpleIntegerProperty sellerId = new SimpleIntegerProperty();
//private Seller seller; //not working
...
//setters and getters here
...
}
을 : 그리고 여기 내 POJO 객체의
context.select()
.from(CLIENTS)
.join(SELLERS)
.on(CLIENTS.ID.eq(SELLERS.ID))
.fetchInto(Client.class);
내가 내가 원하는 것을 얻을 변경해야합니까?
'클라이언트'는 '판매자'를 개체로 사용합니다. DB에는'int'로서'seller_id'가 있습니다. JOOQ가 자동으로 해결합니까? – bradimus
@bradimus 판매자 ID를 자동으로 int로 해석하지만 클라이언트 클래스에서 볼 수 있듯이 판매자 셀러를 추가하려고 시도했지만 해결되지 않았습니다. – user3626048