Non-static method requires a target., NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object target)

511 views
Skip to first unread message

F.B. ten Kate

unread,
Jul 9, 2010, 8:30:29 AM7/9/10
to nhusers
I've been getting this error sometimes and i have no idea why this is
happening.

The project is rather large so i cannot post all the code/mappings
here but what i can do is post the piece of code where the exception
is occurring (if i trust .NET).

Here is Exception + stacktrace:

Exception message:
Exception occurred getter of
Common.Backoffice.Entities.DomainObject.ID

InnerException(s):
Non-static method requires a target.



StackTrace: at
NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object
target)
at
NHibernate.Tuple.Entity.AbstractEntityTuplizer.GetIdentifier(Object
entity)
at
NHibernate.Persister.Entity.AbstractEntityPersister.GetIdentifier(Object
obj, EntityMode entityMode)
at NHibernate.Type.EntityType.IsEqual(Object x, Object y,
EntityMode entityMode, ISessionFactoryImplementor factory)
at NHibernate.Type.ComponentType.IsEqual(Object x, Object y,
EntityMode entityMode, ISessionFactoryImplementor factory)
at NHibernate.Engine.EntityKey.Equals(Object other)
at System.Collections.Generic.ObjectEqualityComparer`1.Equals(T x,
T y)
at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key,
TValue& value)
at NHibernate.Engine.StatefulPersistenceContext.GetEntity(EntityKey
key)
at
NHibernate.Event.Default.AbstractSaveEventListener.PerformSave(Object
entity, Object id, IEntityPersister persister, Boolean
useIdentityColumn, Object anything, IEventSource source, Boolean
requiresImmediateIdAccess)
at
NHibernate.Event.Default.AbstractSaveEventListener.SaveWithGeneratedId(Object
entity, String entityName, Object anything, IEventSource source,
Boolean requiresImmediateIdAccess)
at
NHibernate.Event.Default.DefaultMergeEventListener.EntityIsTransient(MergeEvent
event, IDictionary copyCache)
at
NHibernate.Event.Default.DefaultMergeEventListener.EntityIsDetached(MergeEvent
event, IDictionary copyCache)
at
NHibernate.Event.Default.DefaultMergeEventListener.OnMerge(MergeEvent
event, IDictionary copyCache)
at NHibernate.Impl.SessionImpl.FireMerge(IDictionary copiedAlready,
MergeEvent event)
at NHibernate.Impl.SessionImpl.Merge(String entityName, Object obj,
IDictionary copiedAlready)
at
NHibernate.Engine.CascadingAction.MergeCascadingAction.Cascade(IEventSource
session, Object child, String entityName, Object anything, Boolean
isCascadeDeleteEnabled)
at NHibernate.Engine.Cascade.CascadeToOne(Object child, IType type,
CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled)
at NHibernate.Engine.Cascade.CascadeAssociation(Object child, IType
type, CascadeStyle style, Object anything, Boolean
isCascadeDeleteEnabled)
at NHibernate.Engine.Cascade.CascadeProperty(Object child, IType
type, CascadeStyle style, Object anything, Boolean
isCascadeDeleteEnabled)
at NHibernate.Engine.Cascade.CascadeCollectionElements(Object
child, CollectionType collectionType, CascadeStyle style, IType
elemType, Object anything, Boolean isCascadeDeleteEnabled)
at NHibernate.Engine.Cascade.CascadeCollection(Object child,
CascadeStyle style, Object anything, CollectionType type)
at NHibernate.Engine.Cascade.CascadeAssociation(Object child, IType
type, CascadeStyle style, Object anything, Boolean
isCascadeDeleteEnabled)
at NHibernate.Engine.Cascade.CascadeProperty(Object child, IType
type, CascadeStyle style, Object anything, Boolean
isCascadeDeleteEnabled)
at NHibernate.Engine.Cascade.CascadeOn(IEntityPersister persister,
Object parent, Object anything)
at
NHibernate.Event.Default.DefaultMergeEventListener.CascadeOnMerge(IEventSource
source, IEntityPersister persister, Object entity, IDictionary
copyCache)
at
NHibernate.Event.Default.DefaultMergeEventListener.EntityIsDetached(MergeEvent
event, IDictionary copyCache)
at
NHibernate.Event.Default.DefaultMergeEventListener.OnMerge(MergeEvent
event, IDictionary copyCache)
at
NHibernate.Event.Default.DefaultMergeEventListener.OnMerge(MergeEvent
event)
at NHibernate.Impl.SessionImpl.FireMerge(MergeEvent event)
at NHibernate.Impl.SessionImpl.Merge(String entityName, Object obj)
at NHibernate.Impl.SessionImpl.Merge(Object obj)
at DirectPay.Backoffice.Repository.Repository`1.Merge(T entity) in
D:\Projecten\DirectPay\branches\Folkert\solution\Source
\DirectPay.Backoffice.Repository\Repository.cs:line 99


Here is the code of the DomainObject where .NET wants me to look but
somehow i have the feeling the fault does not originate here.

public abstract class DomainObject
{
private int? _id;

/// <summary>
/// Gets or sets the ID.
/// </summary>
/// <value>The ID.</value>
[XmlElement("id")]
public virtual int? ID
{
get { return _id; }
set
{
_id = value;
_oldHashCode = null;
}
}

public override bool Equals(object obj)
{
if(obj == null) return false;
if (!(GetType().IsInstanceOfType(obj))) return false;
return ((DomainObject)obj).ID.Equals(ID);
}

private int? _oldHashCode;
public override int GetHashCode()
{
// Once we have a hash code we'll never change it

if (_oldHashCode.HasValue)
return _oldHashCode.Value;

bool thisIsTransient = Equals(ID, 0);
// When this instance is transient, we use the base
GetHashCode()
// and remember it, so an instance can NEVER change its
hash code.

if (thisIsTransient)
{
_oldHashCode = base.GetHashCode();
return _oldHashCode.Value;
}
return this.ToString().GetHashCode() + ID.GetHashCode();
}
}

I´ve been stuck on this exception for a few days now and i´m
absolutely out of ideas, i´m not even sure which object is causing the
exceptions at this point.

If anyone can point me in the right direction i would be ever so
gratefull.

Greetings,

F.B. ten Kate

kor

unread,
Jul 9, 2010, 10:47:35 AM7/9/10
to nhusers
why id is nullable? maybe the problem is that

anyhow put same log to identify when this exception is thrown,

F.B. ten Kate

unread,
Jul 9, 2010, 11:02:17 AM7/9/10
to nhusers
That has to do with the fact i didn't (and still don't) wanna use
DTO's, while using these object in webservices. Since the objects
don't have (or need) and id when they are send to the server to be
inserted we made it a nullable int.

It hasn't been a problem before so i doubt it is now.

I'm not able to pin point the problem, it seems the exception is
thrown from NHibernate itself so might actually be a bug. But it's
frustrating the hell out of me.

If i had to gues it has something to do with the following mapping:

<class name="EntityReactionType" table="tbl_Entiteit_Reactie_Type">
<composite-id>
<key-many-to-one name="Entity" column="Entiteit_ID" class="Entity"/
>
<key-many-to-one name="ReactionType" column="Reactie_Type_ID"
class="ReactionType"/>
</composite-id>
<property name="Text" column="Omschrijving"/>
<set name="PossibleResponses"
table="tbl_Entiteit_Response_Reactie_Type" batch-size="50">
<key>
<column name="Bron_Entiteit_ID" sql-type="int"/>
<column name="Bron_Reactie_Type_ID" sql-type="int"/>
</key>
<many-to-many class="EntityReactionType">
<column name="Response_Entiteit_ID"/>
<column name="Response_Reactie_Type_ID"/>
</many-to-many>
</set>
</class>

Since atm for some reason NHibernate is having a hard time inserting
the correct values, for some reason it NULLs the Entity and
ReactionType, not sure why and this might be unrelated but somehow i
doubt that. Maybe NHibernate is NULLing the values somewhere and
expecting them to not be null and trying to call a property/method
somewhere else (thus causing some errors).

kor

unread,
Jul 9, 2010, 11:23:26 AM7/9/10
to nhusers
i continue to don't understand why use nullable id, if you don't need
it dont' read it, i don't understand why you added the complexity to
manage null ids.

anyhow is this exactly the map of the object which throws the
exception ?
no cascade set?
EntityReactionType is ReactionType (in your map thay appear both?

Fabio Maulo

unread,
Jul 9, 2010, 11:39:19 AM7/9/10
to nhu...@googlegroups.com
I can't see the relation between the class you sent us and the mapping you sent us.
The class has a Nullable<int> as POID but in the mapping you are using a composite ID.


--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

F.B. ten Kate

unread,
Jul 12, 2010, 3:20:47 AM7/12/10
to nhusers
There is no direct relationship, i'm developing a form which fills a
Entity object, an entity object among other things has
EntityReactionTypes, when this collection changes (when i add 2 or
more objects to the collection) and try to Merge() (since the session
get's closed after retrieving the Entity). In this merge The error is
thrown, the Entity Mapping is as follows:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="DirectPay.Backoffice.Entities"
namespace="DirectPay.Backoffice.Entities">
<class name="Entity" table="tbl_Entiteit">
<id name="ID" column="Entiteit_ID">
<generator class="increment" />
</id>
<property name="Code" column="Entiteit_Code" />
<property name="Comments" column="Opmerkingen" />
<component name="CompanyDetails">
<component name="Address">
<property name="ZIPCode" column="Vestiging_Postcode"/>
<property name="Street" column="Vestiging_Adres"/>
<property name="City" column="Vestiging_Plaats"/>
<many-to-one name="Country" fetch="join"
column="Vestiging_Land_ID"/>
<component name="HouseNumber">
<property name="Number" column="Vestiging_Huisnummer"/>
</component>
</component>
<many-to-one name="Branch" fetch="join" column="Branche_ID"/>
<many-to-one name="Sector" fetch="join" column ="Sector_ID"/>
<property name="ChamberOfCommerceNumber" column="KvKNummer"/>
<component name="CorrespondenceAddress" class="Address">
<property name="ZIPCode" column="Correspondentie_Postcode"/>
<property name="Street" column="Correspondentie_Adres"/>
<property name="City" column="Correspondentie_Plaats"/>
<many-to-one name="Country" fetch="join"
column="Correspondentie_Land_ID"/>
<component name="HouseNumber">
<property name="Number" column="Correspondentie_Huisnummer"/>
</component>
</component>
<property name="IsLiableToVAT" column="BTWPlichtig_NeeJa"/>
<property name="Name" column="Bedrijfsnaam"/>
<property name="VATNumber" column="BTWNummer"/>
<many-to-one name="TypeOfCompany" fetch="join"
column="Rechtsvorm_ID"/>
</component >
<set cascade="all-delete-orphan" inverse="true"
name="ContactPersons">
<key column="Entiteit_ID"></key>
<one-to-many class="ContactPerson"/>
</set>
<component name="ContactInformation">
<property name="FaxNumber" column="Faxnummer"/>
<property name="TelephoneNumber" column="Telefoonnummer"/>
<property name="EmailAddress" column="Email"/>
</component>
<!--<property name="DateLastEdited" column="DatumWijziging"/>
<property name="IsActive" column="Actief_NeeJa"/>-->
<property name="SearchCode" column="Zoekcode"/>
<property name="SortName" column="Sorteernaam"/>
<set name="BankAccounts" cascade="all-delete-orphan" inverse="true">
<key column="Entiteit_ID"></key>
<one-to-many class="BankAccount"/>
</set>
<one-to-one name="EntityDashboard" constrained="false"/>
<one-to-one name="Contract" constrained="false"/>
<set name="EntityReactionTypes" cascade="all-delete-orphan"
inverse="true">
<key column="Entiteit_ID"></key>
<one-to-many class="EntityReactionType"/>
</set>
</class>
</hibernate-mapping>

On 9 jul, 17:39, Fabio Maulo <fabioma...@gmail.com> wrote:
> I can't see the relation between the class you sent us and the mapping you
> sent us.
> The class has a Nullable<int> as POID but in the mapping you are using a
> composite ID.
>
> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com>
> > .

F.B. ten Kate

unread,
Jul 13, 2010, 10:05:06 AM7/13/10
to nhusers
Made the ID property to be just a regular int instead of a Nullable
Int, but this made no difference what so ever.

I'm pulling out my hairs at the moment it simply does not make any
sense to me >.<

John Davidson

unread,
Jul 13, 2010, 1:39:33 PM7/13/10
to nhu...@googlegroups.com
You should read the documentation for ISession.Merge. I do not think it does what you are hoping it will do. I do not believe you can add a collection while the instance is detached and expect it to work, you probably need to attach it first and then add the collections.

John Davidson

To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

F.B. ten Kate

unread,
Jul 14, 2010, 9:27:06 AM7/14/10
to nhusers
Think i've found the problem, i'm working on an update of an old
legacy database, one where no FK's are implemented.

Reactions are bound to the EntityReactionType, like thus:

<many-to-one name="EntityReactionType">
<column name="Entiteit_ID" not-null="true" />
<column name="Reactie_Type_ID" not-null="true"/>
</many-to-one>

As you can see these fields cannot be NULL, sadly Entiteit_ID seemed
to have NULL values which seemed to be causing this problem.

On 13 jul, 19:39, John Davidson <jwdavid...@gmail.com> wrote:
> You should read the documentation for ISession.Merge. I do not think it does
> what you are hoping it will do. I do not believe you can add a collection
> while the instance is detached and expect it to work, you probably need to
> attach it first and then add the collections.
>
> John Davidson
>
> > <nhusers%2Bunsu...@googlegroups.com<nhusers%252Buns...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages