有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

SpringJava刷新数据库

我正在使用SpringBootMVC和Java

我有一个终点:

@GetMapping("/validate/{idIntRaptMec}")
public ResponseEntity<?> validate(@PathVariable(value="idIntRaptMec") Long idIntRaptMec ){

      //Get the appointment from the table    
      IntRaptMec appointment = intRaptMecService.getPointment(idIntRaptMec);
      (...)
}

当我使用“getPoint(iditraptmec)”时,它通过JPA从数据库中恢复一个对象。在这里之前一切正常

但是,这个方法恢复的对象似乎已经过时了

它的一些属性为NULL,但是数据库中该对象的记录被填充,包括java称为NULL的属性

我认为我必须使用某种类型的“刷新数据库”方法。我不知道是否真的存在,但我感觉JavaSpring引导使用的是“缓存数据库”。这是真的吗?有办法解决这个问题吗

我不能把intraTMEC模型类放在这里,因为它太大了(大约40多个属性)。我没有在这个表中创建它。但我可以向您展示一些返回NULL但在数据库中填充的属性:

@Column(name="CD_EQUIPTO")
 public Long getCdEquipto() {
            return this.cdEquipto;
 }

 public void setCdEquipto(Long cdEquipto) {
        this.cdEquipto = cdEquipto;
 }

 @Column(name="CD_OPERACAO")
 public BigDecimal getCdOperacao() {
    return this.cdOperacao;
 }
 public void setCdOperacao(BigDecimal cdOperacao) {
    this.cdOperacao = cdOperacao;
 }

 @Column(name="CD_UPNIVEL3")
 public String getCdUpnivel3() {
    return this.cdUpnivel3;
 }

 public void setCdUpnivel3(String cdUpnivel3) {
    this.cdUpnivel3 = cdUpnivel3;
 }

我不是在处理交易。与数据库的连接是正确的,因为我可以毫无问题地获取其他对象(来自其他模型)。我正在使用Oracle数据库

这是IntraTMecService类:

@Service
public class IntRaptMecService {

    @Autowired
    IntRaptMecRepository intRaptMecRepository; 

    public IntRaptMec getPointment(Long id) {

            Optional<IntRaptMec> obj = intRaptMecRepository.findById(id);
            return obj.get();

    }
}

这是内部存储类:

@Repository    
public interface IntRaptMecRepository extends JpaRepository<IntRaptMec, Long>{

}

This is the object that I want to get from the Database


共 (1) 个答案

  1. # 1 楼答案

    解决办法是:

    如果使用的是Oracle数据库,则在对数据库表执行任何更新后,必须使用COMMIT;语句保存所做的更改

    使用提交后,对象正确返回