spring-data-jpa2.1.10一对多新增的几种方式对比

本文通过对比分析Spring Data JPA中一对多关系在新增时的两种不同实现方式,展示了如何避免多余的SQL更新操作。方式一在一对多关系中导致额外的更新SQL,而方式二通过调整注解配置,成功消除这一问题。在测试过程中,发现同时配置一对多和多对一会引发栈溢出异常。
摘要由CSDN通过智能技术生成
junit测试代码模板,后面只贴出其中不一样的地方
import com.wn.dao.CustomerRepository;
import com.wn.dao.LinkmanRepository;
import com.wn.domain.Customer;
import com.wn.domain.Linkman;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class JpaManyTest {
   

    @Autowired
    private CustomerRepository customerRepository;

    @Autowired
    private LinkmanRepository linkmanRepository
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值