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: Exception occurred getter of ID: object/target don't match
PostPosted: Tue Dec 02, 2008 7:37 pm 
Newbie

Joined: Tue Nov 18, 2008 5:25 pm
Posts: 1
Location: near Dallas, Texas
We're newbies and have spent most of the day trying to figure this out.

The error is:

Hibernate.PropertyAccessException : Exception occurred getter of Fw.Domain.CmObject.Id
----> System.Reflection.TargetException : Object does not match target type.

Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 2.0.1

Mapping documents:

Code:
   <class name="CmObject" table="CmObject" discriminator-value="0">

      <!--CmObject-->
      <id name="Id">
         <generator class="guid"/>
      </id>
      <discriminator column="Class$" type="Int64"></discriminator>
      <property name="kflidCmObject_Guid" column="Guid$"></property>
...


The class:

Code:
...
   public class CmObject
   {
      // TODO: Change this to something other than a guid.
      public virtual Guid Id { get; set; }
                ...
   }



The repository:

Code:
namespace Fw.Repositories
{
   public class CmObjectRepository : ICmObjectRepository
   {
      public void Add(CmObject cmObject)
      {
         using (ISession session = NHibernateHelper.OpenSession())
         using (ITransaction transaction = session.BeginTransaction())
         {
            session.Save(cmObject);
            transaction.Commit();
         }
      }
   }
}


The unit test:

Code:
   private void CreateInitialData()
   {
      using (ISession session = _sessionFactory.OpenSession())
      using (ITransaction transaction = session.BeginTransaction())
      {
         foreach (CmObject obj in _obj)
            session.Save(obj);
         transaction.Commit();
      }
   }
   
   [TestFixtureSetUp]
   public void TestFixtureSetUp()
   {
      _configuration = new Configuration();
      _configuration.Configure();
      _configuration.AddAssembly("FDO");
      _sessionFactory = _configuration.BuildSessionFactory();
   }

   [SetUp]
   public void SetupContext()
   {
      new SchemaExport(_configuration).Execute(false, true, false, false);
      this.CreateInitialData();
   }

   [Test]
   public void Can_add_new_product()
   {
      //CmPossibilityList cmPossList = new CmPossibilityList();
      CmObject cmObj = new CmObject();

      ICmObjectRepository repository = new CmObjectRepository();
      repository.Add(cmObj);

      // use session to try to load the product
      using (ISession session = _sessionFactory.OpenSession())
      {
         CmObject fromDb = session.Get<CmObject>(cmObj.Id);
         // Test that the product was successfully inserted
         Assert.IsNotNull(fromDb);
         Assert.AreNotSame(cmObj, fromDb);
         Assert.AreEqual(cmObj.kflidCmObject_Class, fromDb.kflidCmObject_Class);
         Assert.AreEqual(cmObj.kflidCmObject_Owner, fromDb.kflidCmObject_Owner);
         Assert.AreEqual(cmObj.kflidCmObject_OwnFlid, fromDb.kflidCmObject_OwnFlid);
      }
   }



Full stack trace of any exception that occurs:

------ Test started: Assembly: TestNHibernate.dll ------

TestCase 'CmObjectRepository_Fixture.Can_add_new_product' failed: TestFixtureSetUp failed in CmObjectRepository_Fixture
TestFixture failed: NHibernate.PropertyAccessException : Exception occurred getter of Fw.Domain.CmObject.Id
----> System.Reflection.TargetException : Object does not match target type.
at NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object target)
at NHibernate.Engine.UnsavedValueFactory.GetUnsavedIdentifierValue(String unsavedValue, IGetter identifierGetter, IType identifierType, ConstructorInfo constructor)
at NHibernate.Tuple.PropertyFactory.BuildIdentifierProperty(PersistentClass mappedEntity, IIdentifierGenerator generator)
at NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass persistentClass, ISessionFactoryImplementor sessionFactory)
at NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory)
at NHibernate.Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass persistentClass, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping mapping)
at NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor factory, IMapping cfg)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
at NHibernate.Cfg.Configuration.BuildSessionFactory()
at CmObjectRepository_Fixture.TestFixtureSetUp() in C:\FwHibernate\Src\FDO\TestNHibernate\TestCmObject.cs:line 69
--TargetException
at System.Reflection.RuntimeMethodInfo.CheckConsistency(Object target)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at NHibernate.Properties.BasicPropertyAccessor.BasicGetter.Get(Object target)

0 passed, 1 failed, 0 skipped, took 2.20 seconds.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 02, 2009 10:32 am 
Newbie

Joined: Fri May 20, 2005 4:20 am
Posts: 2
I'm having exactly the same problem and can't figure it out. Rather than type out a new post, I thought I'd bring this to the top so other people can google it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 02, 2009 11:22 am 
Newbie

Joined: Fri May 20, 2005 4:20 am
Posts: 2
OK it looks like BasicPropertyAccessor is trying to reflect the ID attribute directly from a List<ChildEntity> rather than List<ChildEntity> [0..x].

This was because I configured a child collection as a many-to-one, instead of a bag- stupid error on my part. Would it be possible to have a friendlier error come back?


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.