Spring Data JDBC invert OneToOne navigation

我与影子孤独终老i 提交于 2020-01-05 05:11:06

问题


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


回答1:


There is currently no support for this on the Spring Data JDBC side.

On option that comes to mind is to create a view that already performs the join and has instead of triggers to perform the correct actions on the Child table. You can then map the Child as embedded.



来源:https://stackoverflow.com/questions/59090329/spring-data-jdbc-invert-onetoone-navigation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!