-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: NonUniqueObjectException again
PostPosted: Mon Aug 30, 2004 3:55 am 
Newbie

Joined: Fri Feb 20, 2004 9:03 pm
Posts: 5
Location: Montreal, QC
Hibernate version:
hibernate-2.1.3

Mapping documents:
<hibernate-mapping>
<class name="com.jff.bo.UserBean" table="users" lazy="true">
<cache usage="read-write"/>
<id name="user_id" type="int">
<generator class="native"/>
</id>
<many-to-one name="role" class="com.jff.bo.RoleBean" column="role_id_fk"/>
<property name="login" column="login" type="string" update="false" not-null="true" unique="true"/>
<property name="password" column="password" type="string" not-null="true"/>
<property name="registration_date" column="registration_date" type="timestamp" update="false" />
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
First i call to:
Code:
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        UserBean sessionUser = sessionMgr.getSessionUser(httpServletRequest.getSession(true));
        if (sessionUser != null) {
            userService.reattach(sessionUser);
            modelAndView.addObject("authenticatedUser", sessionUser);
        }
    }

Then from other place:
Code:
    public List getAll() {
        return getHibernateTemplate().loadAll(UserBean.class);
    }


Full stack trace of any exception that occurs:
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 4, of class: com.jff.bo.UserBean
org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:333)
org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:222)
org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:155)
org.springframework.orm.hibernate.HibernateTemplate.lock(HibernateTemplate.java:231)
com.jff.service.dao.hibernate.UserBeanDaoImpl.reattach(Unknown Source)
Name and version of the database you are using:
MySQL 4.X


I put UserBean object to HttpServletRequest session, and then reattach it (getHibernateTemplate().lock(user, LockMode.NONE);

But in some situations UserBean object is already attached to Hibernate session and i get NonUniqueObjectException.

So my question is how can i check is object is already attached (beside checking for LazyInit exception).

_________________
When nothing can possibly go wrong, it will.


Top
 Profile  
 
 Post subject: small update
PostPosted: Mon Aug 30, 2004 4:15 am 
Newbie

Joined: Fri Feb 20, 2004 9:03 pm
Posts: 5
Location: Montreal, QC
Sorry, small update:

Code between sessionFactory.openSession() and session.close():

First i call to:
Code:
    public List getAll() {
        return getHibernateTemplate().loadAll(UserBean.class);
    }


Then from other place:
Code:
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        UserBean sessionUser = sessionMgr.getSessionUser(httpServletRequest.getSession(true));
        if (sessionUser != null) {
            userService.reattach(sessionUser);
            modelAndView.addObject("authenticatedUser", sessionUser);
        }
    }

Full stack trace of any exception that occurs:
Code:
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 4, of class: com.jff.bo.UserBean
   org.springframework.orm.hibernate.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:333)
   org.springframework.orm.hibernate.HibernateAccessor.convertHibernateAccessException(HibernateAccessor.java:222)
   org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:155)
   org.springframework.orm.hibernate.HibernateTemplate.lock(HibernateTemplate.java:231)
   com.jff.service.dao.hibernate.UserBeanDaoImpl.reattach(Unknown Source)
   com.jff.filters.PushUserToViewInterceptor.postHandle(Unknown Source)
   org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:491)
   org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:342)
   org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:318)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
   org.springframework.orm.hibernate.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:117)
   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:73)
   com.opensymphony.module.sitemesh.filter.PageFilter.parsePage(PageFilter.java:142)
   com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:58)

_________________
When nothing can possibly go wrong, it will.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.