Spring 引导命令行运行器未提交事务

Spring boot commandlinerunner not committing transaction

我已经构建了一个实用程序来使用 spring 引导加载一些数据,该实用程序能够打开与数据库的连接并提取数据,但它不会以某种方式提交数据。以下是代码。

我运行它通过以下方式none工作。

java -jar target/someapp-load-dt-0.0.1-SNAPSHOT.jar
mvn spring-boot:run

代码

@SpringBootApplication
public class SomeApplication implements CommandLineRunner {

@Autowired
DataProcessor dataProcessor;

public static void main(String[] args) {
    SpringApplication.run(BroadsoftLoadDtApplication.class, args);
}

@Override
public void run(String... args) throws Exception {
    this.dataProcessor.process();
}
}

DataProcessor.java

@Transactional(propagation = Propagation.REQUIRES_NEW)
@Service
public class DataProcessor {
    @Autowired
    private SomeDao bshServicePackDAO;

    @Transactional(readOnly = false)
    public void process() {
        bshServicePackDAO.findAll();//gets the data fine
        bshServicePackDAO.save(new SomeDto(1,2,3));
    }
}

SomeDao.java

@Repository
public interface SomeDao extends CrudRepository<SomeDto, Integer> {
}

application.properties

#Basic Spring Boot Config for Oracle
spring.datasource.url= jdbc:oracle:thin:@DBL.LOCAL:1521/test
spring.datasource.username=test
spring.datasource.password=xya
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver

#hibernate config
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
#logging.level.org.hibernate.SQL=DEBUG
#logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE

我有带有多对多映射的@JoinTable,我不得不更改关系的owner。提交开始工作。过去 Two.java 有 @ManytoMany 映射并且所有者是二,我必须将其更改为以下内容才能工作。现在one.voiceFeatures.add(两个);提交工作正常。

Class One.java

@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinTable(name = "join_table", schema = "int", joinColumns = {
        @JoinColumn(name = "service_pack_id", referencedColumnName = "service_pack_id", nullable = false)
}, inverseJoinColumns = {
        @JoinColumn(name = "voice_feature_id", referencedColumnName = "voice_feature_id", nullable = false)
})
public Set<Two> voiceFeatures;

在Two.java

@ManyToMany(mappedBy = "voiceFeatures", fetch = FetchType.LAZY)
public Set<One> servicePacks;