日期:2014-05-19  浏览次数:20793 次

请问,为什么一个超链接的action被执行了两次?
HTML code
<a href="competitions/findByUserIdBy.action" target="main">赛事管理</a>



配置文件:


XML code
<action name="findByUserIdBy" class="competitionsAction"
            method="findByUserId">
            <result name="success">/web/competitions/competition.jsp
            </result>
            <result name="input">/web/competitions/deleteError.jsp</result>
        </action>


action:
Java code

public String findByUserId() throws Exception {
        try {
            Map session = ActionContext.getContext().getSession();
            String ids = session.get("userId").toString();
            id = Long.parseLong(ids);
            listCompetitions = this.competitionsService.findByUserId(id);
        } catch (Exception e) {
            e.printStackTrace();
            return INPUT;
        }
        return SUCCESS;
    }



执行上面的那个超链接的时候,后台打印出了两条一样的SQL语句。

SQL code
Hibernate: 
    select
        competitio0_.id as id10_,
        competitio0_.name as name10_,
        competitio0_.startTime as startTime10_,
        competitio0_.endTime as endTime10_,
        competitio0_.address as address10_,
        competitio0_.sponsors as sponsors10_,
        competitio0_.organizer as organizer10_,
        competitio0_.coOrganizer as coOrgani8_10_,
        competitio0_.status as status10_,
        competitio0_.remarks as remarks10_,
        competitio0_.userId as userId10_ 
    from
        sportSys.dbo.competitions competitio0_ 
    where
        competitio0_.userId='9'
Hibernate: 
    select
        competitio0_.id as id10_,
        competitio0_.name as name10_,
        competitio0_.startTime as startTime10_,
        competitio0_.endTime as endTime10_,
        competitio0_.address as address10_,
        competitio0_.sponsors as sponsors10_,
        competitio0_.organizer as organizer10_,
        competitio0_.coOrganizer as coOrgani8_10_,
        competitio0_.status as status10_,
        competitio0_.remarks as remarks10_,
        competitio0_.userId as userId10_ 
    from
        sportSys.dbo.competitions competitio0_ 
    where
        competitio0_.userId='9'

百思不得其解啊,不知道为啥,

因为,我的一个更新报了如下的错误:很是烦人。我就怀疑是这个两次执行的问题引起的。谢谢~

XML code
a different object with the same identifier value was already associated with the session: [com.yaxing.entity.Competitions#130]; nested exception is org.hibernate.NonUniqueObjectException:


------解决方案--------------------

在hibernate中同一个session里面有了两个相同标识但是是 不同实体时就会出现如标题的错误.

这个异常发生当你用session.load 或 session.get加载一个对象时 而又尝试着 
session.update or session.lock 操作此对象

解决:
请不要用session加载对对象当你引用或再次使用该对象

------解决方案--------------------
不同的对象与相同的标识符值已经与会话关联起来

我以前也遇到过,忘记怎么解决了 ⊙﹏⊙b汗
------解决方案---