-->
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.  [ 3 posts ] 
Author Message
 Post subject: MAJOR PROBLEM in NHibernate 1.2.0.CR1
PostPosted: Thu Mar 29, 2007 5:06 am 
Beginner
Beginner

Joined: Fri Jan 19, 2007 10:45 am
Posts: 23
Hello,
I've found a problem when using an entity having a CompositeId having a property "key-many-to-one".

<class name="Tariff" table="CATALOGUE_GENERAL">
<cache usage="read-write" region="Reference"/>
<composite-id name="CompId" class="CompositeId">
<key-property name="Id" column="ID_CAT_ELEMENT"/>
<key-many-to-one name="Category" class="Category" column="CD_CAT_FRAIS"/>
</composite-id>

The problem is : if the entity goes in the cache, then the object is not retreive by the method ICache.Get(object key) (using SysCache.cs)

The problem has the following origin :
1) the test "if (key.Equals(de.Key))" in SysCache.cs returns false
2) Key is a CacheKey, in its Equals implementation it is the part "this.type.Equals(this.key, that.key) " that return false.
2) type is a ComponentType, in the Equals implementation it is the
this.propertyTypes[i].Equals(this.getters[i].Get(x), this.getters[i].Get(y)))
when propertyTypes[i] = ManyToOneType that return false.
that means : instanceOfManyToOneType.Equals(Category1, Category2) return false ( or Category1 == Category2 return true !)

The reason is because implementation of ManyToOneType.Equals (which is inherited from EntityType.Equals is :
public sealed override bool Equals(object x, object y)
{
return (x == y);
}

this call == operator defined on object ( and not the one defined on Category, operators are not virtual )
If you want to redefine Equals you should redefine :
- Equals + GetHashCode AND == AND =! OPERATORS
WHICH IS NOT DONE ON ENTITYTPYE !!!

Do you agree with me ?


Top
 Profile  
 
 Post subject: Replay:
PostPosted: Thu Mar 29, 2007 9:49 am 
Newbie

Joined: Wed Mar 07, 2007 10:59 pm
Posts: 6
Hi syl74
I think you should create the class inherit IEquatable,and overwrite method Equals(object other)!
like this :
http://www.cnblogs.com/Roping/archive/2 ... 89805.html


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 29, 2007 10:26 am 
Beginner
Beginner

Joined: Fri Jan 19, 2007 10:45 am
Posts: 23
Thanks for your help.
I try to implement IEquatable<T> on my Category object
and on my CompositeId object but it did not change anything...


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