Spring 什么是';Propagation.NEVER以非事务方式执行';你是说春天?

Spring 什么是';Propagation.NEVER以非事务方式执行';你是说春天?,spring,hibernate,spring-boot,spring-data-jpa,spring-transactions,Spring,Hibernate,Spring Boot,Spring Data Jpa,Spring Transactions,在下面的代码中,DeviceService类内的createDevice方法中的保存操作将不会在事务内执行,这意味着该操作不会在事务内执行是什么意思? 是否可以在没有事务的情况下对数据库执行操作 package controller; import model.Device; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; imp

在下面的代码中,DeviceService类内的createDevice方法中的保存操作将不会在事务内执行,这意味着该操作不会在事务内执行是什么意思? 是否可以在没有事务的情况下对数据库执行操作

package controller;

import model.Device;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import service.DeviceService;

@RestController
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    @PostMapping("/devices")
    @ResponseStatus(HttpStatus.CREATED)
    public void createDevice(@RequestBody Device device) {
        deviceService.createDevice(device);
    }
}
--

--

编辑 我正在使用MySQL数据库。 该操作已成功执行。 关于如何在没有事务的情况下执行此操作的详细信息?在场景后面正在做什么?

在事务内部执行操作与不执行事务之间有什么区别

如果存在活动事务,则应引发异常。我从来没有尝试过处理这个问题,我希望拦截器在进入过程中检查事务,如果服务中有dao调用执行它们自己的事务,如果这些调用会为它们抛出异常,我会感到惊讶。看起来您拥有大部分代码,当您尝试它时会发生什么?不,您不能使用非事务性sql/dml,但如果您不指定它们,spring将为您启动事务(针对单个db操作)。@NathanHughes我使用的是MySQL。该操作已成功执行。
package service;

import model.Device;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import repository.DeviceRepository;

@Service
public class DeviceService {
    @Autowired
    private DeviceRepository deviceRepository;
    @Transactional(propagation = Propagation.NEVER)
    public void createDevice(Device device) {
        deviceRepository.save(device);
    }
}
package repository;

import model.Device;
import org.springframework.data.jpa.repository.JpaRepository;
public interface DeviceRepository extends JpaRepository<Device, Integer> {
}
package model;

import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Device {
    @Id
    private Integer id;
    private String name;
}