当repository.save时,Spring Boot + JPA + Hibernate不会提交 [英] Spring Boot + JPA + Hibernate does not commit when repository.save

查看:214
本文介绍了当repository.save时,Spring Boot + JPA + Hibernate不会提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有MySQL的Spring Boot Application + JPA。在我的控制器中,当我发布一个实体时,我可以调用repository.save,并返回创建/更新的对象。

I have a Spring Boot Application + JPA with MySQL. In my controller, when I post an entity I am able to call to repository.save, and I return the "created/updated" object.

但是,当我查看时在数据库中,我看到该对象未更新。

But, when I look at the database, I see that the object is not updated.

这是我的应用程序。yml:

Here is my application.yml:

spring:
  jpa:
    show-sql: true
    generate-ddl: false
    hibernate:
      ddl-auto: none
    properties:
      hibernate.dialect: org.hibernate.dialect.MySQLDialect
      org.hibernate.envers.store_data_at_delete: true
      org.hibernate.envers.global_with_modified_flag: true
      org.hibernate.envers.track_entities_changed_in_revision: true
  datasource:
    initialize: false
    url: jdbc:mysql://${DB_HOST:localhost}:${DB_PORT:3306}/${DB_NAME:databaseName}?createDatabaseIfNotExist=true
    username: ${DB_USERNAME:root}
    password: ${DB_PASSWORD:root}
    driver-class-name: com.mysql.jdbc.Driver
    hikari:
      minimumIdle: 20
      maximumPoolSize: 30
      idleTimeout: 5000
      data-source-properties:
        cachePrepStmts: true
        prepStmtCacheSize: 250
        prepStmtCacheSqlLimit: 2048

您知道我还需要做什么吗?

Do you know what else do I have to do?

这是我的控制器:

@RequestMapping(method = RequestMethod.POST, produces = "application/json")
public MyEntity saveMyEntity(@Valid @RequestBody final MyEntity myEntity) {
    Assert.notNull(myEntity, "The entry cannot be null");
    return myEntityService.save(myEntity);
}

和MyEntityService:

And MyEntityService:

@Override
@UserCanCud
public Entity save(final Entity entity) {
    Assert.notNull(entity);
    final Entity savedEntity = repository.save(entity);
    return savedEntity;
}


推荐答案

我终于找到了解决方案。 ..我尝试更新的实体上面有@Immutable注释...

I finally found the solution... the entity I was trying to update had the @Immutable annotation on it...

这篇关于当repository.save时,Spring Boot + JPA + Hibernate不会提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆