2

I have an existing data scheme I'm reluctant to change. There are two entities/tables: parent and child, with parent having the foreign key column child_id. It's a 1-to-1 relationship.

The problem is: the magic behind the scenes expects the child table to have the foreign key column (the exception mentions a ...JOIN ON child.parent = parent.id). Is it possible to inverse this to match the existing scheme? (I know it is with hibernate, but I'd like to stay with JDBC).

Relevant code:

@Repository
public interface ParentRepository extends CrudRepository<Parent, Long>{
}
@Data
public class Parent {
    @Id
    private Long id;

    private Child child;
}
@Data
public class Child {
    @Id
    private Long id;
}

Somewhat related question: Spring Data JDBC invert OneToMany navigation

4

1 回答 1

1

Spring Data JDBC 端目前不支持此功能。

想到的一个选项是创建一个已经执行连接的视图,而不是触发器来对Child表执行正确的操作。然后,您可以将其映射Child为嵌入的。

于 2019-11-29T07:09:40.260 回答