mysql - hibernate 与我的数据库不同步

标签 mysql hibernate

  @PersistenceContext(unitName = "ServerLayerPU")
  protected EntityManager m_entityManager;

   m_entityManager.persist(entity);
   m_entityManager.flush();

我试图让我的新实体对象与已提交到数据库的内容同步。我最初放入冲洗,我认为这解决了问题,但在更大的测试中问题又出现了。当此实体提交到数据库时,会发生影响另一个表/实体的触发器,我需要反射(reflect)这一点。我该怎么办?

最佳答案

flush() 指示实体管理器检测对托管实体所做的所有更改,并将它们发送到数据库。它不会提交事务,也不会导致从数据库重新读取数据。 (Hibernate 如何知道要重新读取哪些数据?您不希望它重新读取所有内容,以防触发器修改了它插入的数据?)。

您可以使用 refresh() 重新读取实体.

关于mysql - hibernate 与我的数据库不同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10200492/

相关文章:

修改cico dhcp池的php脚本

java - 以下 Hibernate 自定义 ID 生成器代码是否正确?

sql-server - 避免连接失败时出现空指针

java - 无法实例化指定的 TransactionFactory 类 [org.transaction.JDBCTransactionFactory]

MySQL 查询到 SQL Server 查询

php - Linux 上的 MySQL、PHP 和命名管道

php - Android 到 MySQL 土耳其语字符写入为 "?"

mysql - 此错误是什么意思以及如何修复它 "Error in saving to database. error is: The method or operation is not implemented"?

java - 如何修复RapidClipse4 org.hibernate.MappingException : Could not configure overrides from file: hibernate. reveng.xml

java - JPA - 使用 Root、Join 在字段上加入获取