---
title: "session"
author: "神奇九寨沟"
date: "2008-11-13T15:55:52Z"
tags: []
slug: "session"
draft: false
lastmod: "2009-04-02T21:57:16Z"
id: 266643
url: "https://webwork123.iteye.com/blog/266643"
---

抛出异常：
a different object with the same identifier value was already associated with <span style="color:red">the session</span>: 

意思是:session中存在主键值相等但是不是同一个对象的记录,类似于数据库中不能存在两条主键值相等的不同记录一样

一般发生在update的时候

解决方法：
         <span style="color:red">1</span><span style="color:red">.session.update() </span>           改成session.merge()
       
        <span style="color:red">2</span>.把session关闭,只让session一次性管理一条一模一样的记录