spring-boot-starter-data-jpa 插入查询不会将数据保存在数据库中



我正在使用spring-boot-starter-data-jpa。尝试在数据库中插入数据时,实用程序执行时没有任何错误,但数据不会保留在数据库中。我还可以在控制台上看到插入查询我不确定这里到底出了什么问题。

聚甲醛.XML

<dependencies>    
     <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter</artifactId>
     </dependency>
     <!-- Spring data JPA -->
     <dependency>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-data-jpa</artifactId>
          <exclusions>
            <exclusion>
                 <groupId>org.apache.tomcat</groupId>
                 <artifactId>tomcat-jdbc</artifactId>
            </exclusion>
          </exclusions>
     </dependency>
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <scope>runtime</scope>
     </dependency>
     <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <scope>runtime</scope>
      </dependency>
      <dependency>
          <groupId>org.apache.poi</groupId>
          <artifactId>poi-ooxml</artifactId>
          <version>3.15</version>
      </dependency>
 </dependencies>

主类

 @SpringBootApplication
 public class Application implements CommandLineRunner {
    @Autowired
    DataSource dataSource;
    @Autowired
    ElementDetailsRepository elementDetailsDAO;
    @Autowired
    ElementDetailsEntity elementDetailsEntity;
    @Autowired
    ElementDetailsPK elementDetailsPK;
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Application.class, args);
    }
    @Transactional(propagation = Propagation.NESTED)
    @Override
    public void run(String... args) throws Exception {
      for (ExcelPojo excelPojo : listOfExcelElements) {
       if (excelPojo.getRecordType().equalsIgnoreCase("Item")) {
       if (excelPojo.getMarket().equalsIgnoreCase("UK")) {
       Integer elementID = elementDetailsDAO.findDNAElementId(excelPojo.getMarket(), 992,
                                    excelPojo.getGenesisID(), "EN");
                            System.out.println("UK ITEM..." + elementID);
        int flag = elementDetailsDAO.createPIMIDAttributeValue(excelPojo.getMarket(), 1914, excelPojo.getPimID(),elementID, "EN", getCurrentTime(), getUser());
  }
  }

存储 库

    @Repository
    public interface ElementDetailsRepository extends JpaRepository<ElementDetailsEntity,Integer> {
        @Query(value = QueryConstants.findElementId, nativeQuery = true)
        public Integer findDNAElementId(@Param("country_code") String country_code, @Param("config_id") int config_id,
                @Param("import_id") String import_id,@Param("language_code")String language_code);
        @Modifying
        @Query(value = QueryConstants.createPIMIDAttributeValue, nativeQuery = true)
        public int createPIMIDAttributeValue(@Param("countrycode") String countrycode, @Param("configid") int configid,
                @Param("pimid") String attribute_value, @Param("elementid") int elementId,@Param ("languageCode") String language_code,@Param("date") String date,@Param("user") String user);
    }

实体

@Service
@Entity
@Table(name = "element_details")
public class ElementDetailsEntity extends BaseDataObject {
 private static final long serialVersionUID = -8033261173844397824L;
 @EmbeddedId
 private ElementDetailsPK elementDetailsPK;
 @Column(name = "status_id")
 private Integer statusId;
 @Column(name = "attribute_value")
 private String attributeValue;
 @Column(name = "is_dirty")
 private Boolean isDirty;
}

应用程序属性

    spring.datasource.url=jdbc:mysql://localhost:3306/wxb_prod
    spring.datasource.username=root
    spring.datasource.password=admin
    spring.datasource.driver-class-name= com.mysql.cj.jdbc.Driver
    spring.jpa.show-sql=true
    spring.jpa.hibernate.ddl-auto = none
    spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
    logging.level.org.hibernate.SQL=TRACE
    spring.datasource.hikari.connectionTimeout=20000
    spring.datasource.hikari.maximumPoolSize=5

尝试在主类中使用注释@EnableJpaRepositories

最新更新