Spring Data JDBC反转OneToOne导航 [英] Spring Data JDBC invert OneToOne navigation
问题描述
我有一个不愿更改的现有数据方案.有两个实体/表:parent
和child
,其中parent
具有外键列child_id
.这是一对一的关系.
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.
问题是:幕后的魔术希望子表具有外键列(例外提到...JOIN ON child.parent = parent.id
).是否可以反过来匹配现有方案? (我知道它与hibernate一起使用,但我想继续使用JDBC).
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).
相关代码:
@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;
}
一些相关的问题: Spring Data JDBC反转一对多导航
推荐答案
Spring Data JDBC方面目前不支持此功能.
There is currently no support for this on the Spring Data JDBC side.
On选项是创建一个已经执行联接的视图,而不是触发器来对Child
表执行正确的操作.
然后,您可以
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.
这篇关于Spring Data JDBC反转OneToOne导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!