-->
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.  [ 7 posts ] 
Author Message
 Post subject: NonUniqueObjectException
PostPosted: Tue May 04, 2004 7:19 am 
Beginner
Beginner

Joined: Sun May 02, 2004 8:04 am
Posts: 36
Hi,

I'm trying to create a new "group" object in my database which contains a "SportletRoleList" set.

My mapping file for SportletGroup looks like:

<hibernate-mapping>
<class
name="org.gridlab.gridsphere.portlet.impl.SportletGroup"
table="sportletgroup"
>

<id
name="oid"
column="gsoid"
type="java.lang.String"
length="32"
>
<generator class="uuid.hex"/>

</id>

<property name="Name" type="string" column="name"/>
<property name="Public" type="boolean" column="ispublic"/>

<set name="portletRoleList" table="portletrolelist" cascade="all">
<key column="role_oid"/>
<many-to-many column="role_info" class="org.gridlab.gridsphere.portlet.impl.SportletRoleInfo"/>
</set>


</class>
</hibernate-mapping>

and mapping for SportletRoleInfo is:

<hibernate-mapping>
<class
name="org.gridlab.gridsphere.portlet.impl.SportletRoleInfo"
table="portletroleinfo"
>

<id
name="oid"
column="gsoid"
type="java.lang.String"
length="32"
>
<generator class="uuid.hex"/>

</id>

<property name="PortletClass" type="string" column="portletclass"/>
<property name="Role" type="string" column="portletrole"/>

</class>
</hibernate-mapping>

My Java code looks like:

public PortletGroup createGroup(String groupName, Set portletRoleList) {
SportletGroup group = getSportletGroupByName(groupName);
if (group == null) {
group = new SportletGroup();
group.setName(groupName);
group.setPublic(true);
group.setPortletRoleList(portletRoleList);
Transaction tx = null;
Session session = null;
try {
session = factory.openSession();
tx = session.beginTransaction();
tx.saveObject(group)

} catch (Exception e) {
String msg = "Error creating group " + groupName;
if (tx != null) {
tx.rollback();
} finally {
session.close();
}
}
return group;
}


and then I get the following stack trace:


104646 [http8080-Processor4] (SportletLog.java:138) ERROR org.gridlab.gridsphere.core.persistence.hibernate.PersistenceManagerRdbmsImpl - Could not complete transaction: net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: , of class: org.gridlab.gridsphere.portlet.impl.SportletRoleInfo
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: , of class: org.gridlab.gridsphere.portlet.impl.SportletRoleInfo
at net.sf.hibernate.impl.SessionImpl.checkUniqueness(SessionImpl.java:1666)
at net.sf.hibernate.impl.SessionImpl.doUpdateMutable(SessionImpl.java:1435)
at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1462)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1385)


Any help is greatly appreciated, thanks Jason


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 04, 2004 9:23 pm 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
Could be a little off here... but i don't see hibernate transaction having a "saveObject(obj) " method on it.

Hib Code typically looks like :

sess.save(new object)
tx.commit();


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 5:59 am 
Beginner
Beginner

Joined: Sun May 02, 2004 8:04 am
Posts: 36
what is the diffference betwen this:

Group g = new Group();
sessi.save(g);

and

sess.save(new Group());

I don't think there is any...


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 9:15 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
Jason,
there is no difference, I was just wondering what
tx.saveObject is... since I don't see the transaction object having that method...

James


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 9:26 am 
Beginner
Beginner

Joined: Sun May 02, 2004 8:04 am
Posts: 36
Whoops I'm sorry-- that should be just save() not saveObject. Basically do you have any idea what exactly a NonUniqueObjectException is and how that happens maybe?

Thanks Jason


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 11:47 am 
Beginner
Beginner

Joined: Thu Jan 22, 2004 8:22 pm
Posts: 48
Perhaps you need to set a unsaved-value. I use database sequences but all my ids look like the following.


Code:
<id column="ID" name="id" type="integer" unsaved-value="-1" >
   <generator class="sequence" >
      <param name="sequence">DB_SEQUENCE</param>
   </generator>
</id>


Notice the unsave-value="-1". Witout this Hibernate doesn't know to generate a id for the new object and I get errors like yours.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 6:01 pm 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
Jason,
Typically i've seen this when essentially exactly what the error message states is happening. SOmehow, an object with the same identifier is loaded twice, but they are not == (the same pointer).

I'd look into your identifier strategy... potentially you also don't have the key properly defined also...

I've never used the hex uuid thing... so i can't help much there.

Good luck.
James


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.