2016-08-11 255 views
2

在我的代码中,我试图更新我的实体,但数据没有保存在数据库中。 检查日志也没有异常。 也尝试@Transaction注释,但它不起作用。Spring JPA Crud Repository save()不更新实体

方法保存调用

public void uploadBill(Long quoteId, MultipartFile multiPartFile) { 
    try { 
     ServiceQuote serviceQuote = serviceQuoteRepository.findOne(quoteId); 

     String extension = ""; 
     if (multiPartFile.getOriginalFilename().lastIndexOf(".") != -1) { 
      extension = multiPartFile.getOriginalFilename().substring(
        multiPartFile.getOriginalFilename().lastIndexOf("."), 
        multiPartFile.getOriginalFilename().length()); 
     } 
     String filename = SERVICING_BILL_FILE_PREFIX 
       + serviceQuote.getReferenceNo() + extension; 
     filename = AmazonS3Util.uploadBill(multiPartFile, filename); 

     serviceQuote.setBillPath(filename); 
     serviceQuoteRepository.save(serviceQuote); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

这里serviceQuoteRepository是JPA CRUD repositorty

@Repository 
public interface ServiceQuoteRepository extends CrudRepository<ServiceQuote, Long> {} 

请建议,这可能是可能的修复。

+1

您可以将这些行添加到您的application.properties并在保存到问题后粘贴输出吗? “spring.jpa.properties.hibernate.show_sql = true spring.jpa.properties.hibernate.use_sql_comments = true spring.jpa.properties.hibernate.format_sql = true spring.jpa.properties.hibernate.type = trace” – Journeycorner

+0

“你确定实体没有保存(用数据库工具重新检查它,确保视图已刷新)? – Journeycorner

+0

@Journeycorner我拥有application.properties中的所有道具。我查了很多次实体没有被更新的值保存。 –

回答

0

有没有问题有关粗劣存储库。实际上,在上传方法之后,另一个服务正在同时更新具有空票据路径的实体,所以我总是看到空列。在调试了几个小时之后才发现问题。

+0

发生这种事时我讨厌它。 – eflat