-->
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.  [ 4 posts ] 
Author Message
 Post subject: Save2UpdateCopy() has problem deal with <Map>
PostPosted: Fri May 27, 2005 1:12 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 10:42 am
Posts: 54
I have a property mapped like this:
<map name="ChildCodes" table="APMDATA.CODE_DESC" sort="natural" lazy="true" cascade="none">
<jcs-cache usage="read-write" />
<key column="CODE_TYPE_ID" />
<index column="ID" type="Int32" />
<one-to-many class="BMO.BookCredit.APMSCode.AbstractAPMSCode, TestNHibernate" />
</map>
As using <Map>, the property will get set a NHibernate.Collection.SortedMap instance.

When I do Save2UpdateCopy(), I trace into PersistentCollectionType.Copy(), cause SortedMapType & MapType don't have overrided Copy() method. In this method, there are one line:
IList originalCopy = new ArrayList( (IList) original );
but the orignal object type NHibernate.Collection.SortedMap is not IList. It cause Cast error.

Is this a problem or I didn't use it right?


Top
 Profile  
 
 Post subject: compare to Hibernate
PostPosted: Sun May 29, 2005 1:08 am 
Regular
Regular

Joined: Thu Dec 02, 2004 10:42 am
Posts: 54
In Hibernate, the java.util.Collection is used in PersistentCollectionType.copy(). And java.util.Collection has the method add().

On .Net side, ICollection doesn't have Add(), I think that's why it got changed to IList.

But IList is not the common base interface.

I made a dirty modification like this, the other way is override this Copy() method in NHibernate.Type.MapType:
public override object Copy( object original, object target, ISessionImplementor session, object owner, IDictionary copiedAlready )
{
object retResult = null;
if ( original == null )
{
return null;
}
if ( !NHibernateUtil.IsInitialized( original ) )
{
return target;
}

IType elemType = GetElementType( session.Factory );
if ( original is IList )
{
IList originalCopy = new ArrayList( (IList) original );
IList result = target == null ? (IList) Instantiate( session, session.Factory.GetCollectionPersister( role ) ) : (IList) target;
result.Clear();
foreach ( object obj in originalCopy )
{
result.Add( elemType.Copy( obj, null, session, owner, copiedAlready ) );
}
retResult = result;
}
else if (original is IDictionary)
{
IDictionary originalCopy = new Hashtable((IDictionary) original);
IDictionary result = target == null ? (IDictionary) Instantiate( session, session.Factory.GetCollectionPersister( role ) ) : (IDictionary) target;
result.Clear();
foreach ( object key in originalCopy.Keys )
{
object newObj = elemType.Copy(originalCopy[key], null, session, owner, copiedAlready );
result[key] = newObj;
}
retResult = result;

}
return retResult;
}
=========================
Hibernate 3 has depricate SaveOrUpdateCopy(), use Merg() instead. Is there any enhancement for Hibernate3 in changing this? I havn't got time to investigate yet. Anyone know about it already?

What is the plan for NHibernate to keep up to Hibernate 3.x?


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 29, 2005 7:18 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
It looks like a bug, please create a JIRA issue


Top
 Profile  
 
 Post subject: A JIRA bug has been created.
PostPosted: Sun May 29, 2005 3:52 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 10:42 am
Posts: 54
I hope it can be resolved before release 1. Thx

http://jira.nhibernate.org/browse/NH-293


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.