-->
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.  [ 1 post ] 
Author Message
 Post subject: Collections Still Killin' Me! Please Help!?!?!
PostPosted: Sat May 17, 2008 12:36 am 
Newbie

Joined: Tue May 13, 2008 10:25 pm
Posts: 2
I keep struggling when mapping my collections using NHibernate. Please see this simple example and call stack. Is this a bug in NHibernate?

Hibernate version:
1.2.1

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
  <class name="Recipe.Recipe, Recipe" table="Recipes" lazy="false" polymorphism="implicit">
    <id name="RecipeName" column="RecipeName" type="String">
      <generator class="assigned" />
    </id>
    <component name="Ingredients">
      <array name="Ingredient" table="Ingredients">
        <key column="RecipeNameFK"/>
        <index column="IngredientIndex"/>
        <composite-element class="Recipe.Ingredient, Recipe">
          <property name="IngredientName" column="IngredientName" type="String" />
        </composite-element>
      </array>
    </component>
  </class>

  <class name="Recipe.Ingredient, Recipe" table="Ingredients" lazy="false" polymorphism="implicit">
    <id name="IngredientName" column="IngredientName" type="String">
      <generator class="assigned" />
    </id>
  </class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():

Code:
            using (ITransaction transaction = _session.BeginTransaction())
            {
                Recipe recipe = new Recipe();
                recipe.RecipeName = "Pesto";
                recipe.Ingredients.Ingredient = new Ingredient[] {
                    new Ingredient("Basil"),
                    new Ingredient("Pine Nuts"),
                    new Ingredient("Olive Oil"),
                    new Ingredient("Cheese")
                };

                _session.Save(recipe);
                transaction.Commit();
            }


Full stack trace of any exception that occurs:
Quote:
Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
at NHibernate.Impl.SessionImpl.UpdateReachableCollection(IPersistentCollection coll, IType type, Object owner)
at NHibernate.Impl.FlushVisitor.ProcessCollection(Object collection, CollectionType type)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.AbstractVisitor.ProcessComponent(Object component, IAbstractComponentType componentType)
at NHibernate.Impl.AbstractVisitor.ProcessValue(Object value, IType type)
at NHibernate.Impl.AbstractVisitor.ProcessValues(Object[] values, IType[] types)
at NHibernate.Impl.SessionImpl.FlushEntity(Object obj, EntityEntry entry)
at NHibernate.Impl.SessionImpl.FlushEntities()
at NHibernate.Impl.SessionImpl.FlushEverything()
at NHibernate.Impl.SessionImpl.Flush()
at NHibernate.Transaction.AdoTransaction.Commit()
at Recipe.HibernateDriver.StoreSomething() in Q:\Report\DefinitionDatabase\NHibernate\Recipe\HibernateDriver.cs:line 65
at Recipe.Program.Main(String[] args) in Q:\Report\DefinitionDatabase\NHibernate\Recipe\Program.cs:line 14


Name and version of the database you are using:
SQLite v3

The generated SQL (show_sql=true):
Code:
CREATE TABLE Recipes (
  RecipeName       text PRIMARY KEY NOT NULL
);

CREATE TABLE Ingredients (
  IngredientName   text PRIMARY KEY NOT NULL,
  RecipeNameFK     text,
  IngredientIndex  integer
);


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.