不能修改持久化对象的主键

org.springframework.orm.hibernate4.HibernateSystemException: identifier of an instance of com.thinkgem.jeesite.modules.sys.entity.Office was altered from 3d788bc64d8e4394ac9d5a2703cf45f1 to 231650e2359245dd813af4b8d44f54b6; nested exception is org.hibernate.HibernateException: identifier of an instance of com.thinkgem.jeesite.modules.sys.entity.Office was altered from 3d788bc64d8e4394ac9d5a2703cf45f1 to 231650e2359245dd813af4b8d44f54b6



遇到这个问题很是苦恼,现在了解的是不能修改持久化对象的主键,主要是因为springFramwork中处理一级session的dirty数据,出现错误,解决的办法,dao.clear().


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Symfony 是一个用 PHP 编写的开源 PHP Web 应用程序框架。它提供了一组工具和库,可以帮助开发者快速构建、部署和维护 Web 应用程序。 在 Symfony 中进行增删改查操作需要使用 Doctrine ORM(对象关系映射)。Doctrine ORM 是 Symfony 默认的持久化层,在数据库和对象之间建立映射关系,提供了方便的 API 来进行数据库操作。 下面是一个示例代码,演示了如何使用 Symfony 和 Doctrine ORM 进行增删改查操作: 1. 添加数据(Create): ```php // 在控制器中引入 Doctrine use App\Entity\YourEntity; use Doctrine\ORM\EntityManagerInterface; // 创建实体对象并设置属性 $yourEntity = new YourEntity(); $yourEntity->setProperty1('value1'); $yourEntity->setProperty2('value2'); // 获取 Doctrine EntityManager $entityManager = $this->getDoctrine()->getManager(); // 将实体对象持久化到数据库 $entityManager->persist($yourEntity); $entityManager->flush(); ``` 2. 查询数据(Read): ```php // 在控制器中引入 Doctrine use App\Repository\YourEntityRepository; // 获取实体对象的仓库 $yourEntityRepository = $this->getDoctrine()->getRepository(YourEntity::class); // 查询所有实体对象 $yourEntities = $yourEntityRepository->findAll(); ``` 3. 更新数据(Update): ```php // 在控制器中引入 Doctrine use App\Entity\YourEntity; use Doctrine\ORM\EntityManagerInterface; // 获取 Doctrine EntityManager $entityManager = $this->getDoctrine()->getManager(); // 根据实体的主键获取实体对象 $yourEntity = $entityManager->getRepository(YourEntity::class)->find($id); // 修改实体对象的属性 $yourEntity->setProperty1('new value1'); $yourEntity->setProperty2('new value2'); // 更新实体对象到数据库 $entityManager->flush(); ``` 4. 删除数据(Delete): ```php // 在控制器中引入 Doctrine use App\Entity\YourEntity; use Doctrine\ORM\EntityManagerInterface; // 获取 Doctrine EntityManager $entityManager = $this->getDoctrine()->getManager(); // 根据实体的主键获取实体对象 $yourEntity = $entityManager->getRepository(YourEntity::class)->find($id); // 从数据库中删除实体对象 $entityManager->remove($yourEntity); $entityManager->flush(); ``` 以上是使用 Symfony 和 Doctrine ORM 进行增删改查操作的基本示例。你可以根据自己的业务需求进行相应的修改和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值