-->
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.  [ 5 posts ] 
Author Message
 Post subject: Composite-Element not being persisted
PostPosted: Tue Jan 09, 2007 7:59 pm 
Newbie

Joined: Tue Jan 09, 2007 7:38 pm
Posts: 5
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 1.2 beta build from source forge

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="NHibernateCETest.ProjectInclude, NHibernateCETest" table="ProjectIncludes" lazy="false">
      <id name="IncludeID" column="ID" unsaved-value="0" access="field">
         <generator class="native" />
      </id>
      <list name="ParmArr" cascade="all" table="ProjectParameters" lazy="false" inverse="true">
         <key column="ProjectID" />
         <index column="dex" />
         <composite-element class="NHibernateCETest.ProjectParameter, NHibernateCETest">
            <property name="name" column="Name" access="field"/>
            <property name="val" column="Val" access="field"/>
         </composite-element>
      </list>
   </class>
</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
         ProjectInclude project = MakeProject();
         object key = ises.Save(project);
         ises.Clear();
         ProjectInclude p2 = ises.Get(typeof(ProjectInclude), key) as ProjectInclude;
         Assert.AreNotEqual(0, p2.ParmArr.Count, "No values returned");
         Assert.IsTrue(project.Equals(p2));



Name and version of the database you are using:
MS SQL Server 2005

The generated SQL (show_sql=true):
Insert statement, select statement, look accurate, the problem is one that is missing.

Debug level Hibernate log excerpt:
Code:
2007-01-09 17:29:06,987 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - saving [NHibernateCETest.ProjectInclude#<null>]
2007-01-09 17:29:07,050 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - executing insertions
2007-01-09 17:29:07,050 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - processing cascades for: NHibernateCETest.ProjectInclude
2007-01-09 17:29:07,050 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - done processing cascades for: NHibernateCETest.ProjectInclude
2007-01-09 17:29:07,065 [TestRunnerThread] DEBUG NHibernate.Impl.WrapVisitor [(null)] <(null)> - Wrapped collection in role: NHibernateCETest.ProjectInclude.ParmArr
2007-01-09 17:29:07,081 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Inserting entity: NHibernateCETest.ProjectInclude (native id)
2007-01-09 17:29:07,097 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened new IDbCommand, open IDbCommands: 1
2007-01-09 17:29:07,097 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Building an IDbCommand object for the SqlString: INSERT INTO ProjectIncludes DEFAULT VALUES; select SCOPE_IDENTITY()
2007-01-09 17:29:07,097 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Dehydrating entity: [NHibernateCETest.ProjectInclude#<null>]
2007-01-09 17:29:07,112 [TestRunnerThread] DEBUG NHibernate.Connection.DriverConnectionProvider [(null)] <(null)> - Obtaining IDbConnection from Driver
2007-01-09 17:29:07,456 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened IDataReader, open IDataReaders: 1
2007-01-09 17:29:07,472 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Natively generated identity: 119
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Driver.NHybridDataReader [(null)] <(null)> - running NHybridDataReader.Dispose()
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDataReader, open IDataReaders :0
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDbCommand, open IDbCommands: 0
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - processing cascades for: NHibernateCETest.ProjectInclude
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - cascading to collection: NHibernateCETest.ProjectInclude.ParmArr
2007-01-09 17:29:07,487 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - done processing cascades for: NHibernateCETest.ProjectInclude
2007-01-09 17:29:07,503 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - loading [ProjectInclude#119]
2007-01-09 17:29:07,503 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - attempting to resolve [ProjectInclude#119]
2007-01-09 17:29:07,503 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - object not resolved in any cache [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,503 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Fetching entity: [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,503 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - loading entity: [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,518 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened new IDbCommand, open IDbCommands: 1
2007-01-09 17:29:07,518 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Building an IDbCommand object for the SqlString: SELECT projectinc0_.ID as ID0_0_ FROM ProjectIncludes projectinc0_ WHERE projectinc0_.ID=?
2007-01-09 17:29:07,534 [TestRunnerThread] INFO  NHibernate.Loader.Loader [(null)] <(null)> - SELECT projectinc0_.ID as ID0_0_ FROM ProjectIncludes projectinc0_ WHERE projectinc0_.ID=@p0
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened IDataReader, open IDataReaders: 1
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - processing result set
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - result set row: 0
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - result row: 119
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - Initializing object from DataReader: [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - Hydrating entity: NHibernateCETest.ProjectInclude#119
2007-01-09 17:29:07,581 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - done processing result set (1 rows)
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Driver.NHybridDataReader [(null)] <(null)> - running NHybridDataReader.Dispose()
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDataReader, open IDataReaders :0
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDbCommand, open IDbCommands: 0
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - total objects hydrated: 1
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - resolving associations for: [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - creating collection wrapper:[NHibernateCETest.ProjectInclude.ParmArr#119]
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - initializing collection [NHibernateCETest.ProjectInclude.ParmArr#119]
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - checking second-level cache
2007-01-09 17:29:07,597 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - collection not cached
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - loading collection: [NHibernateCETest.ProjectInclude.ParmArr#119]
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened new IDbCommand, open IDbCommands: 1
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Building an IDbCommand object for the SqlString: SELECT parmarr0_.ProjectID as ProjectID__0_, parmarr0_.Name as Name0_, parmarr0_.Val as Val0_, parmarr0_.dex as dex__0_ FROM ProjectParameters parmarr0_ WHERE parmarr0_.ProjectID=?
2007-01-09 17:29:07,612 [TestRunnerThread] INFO  NHibernate.Loader.Loader [(null)] <(null)> - SELECT parmarr0_.ProjectID as ProjectID__0_, parmarr0_.Name as Name0_, parmarr0_.Val as Val0_, parmarr0_.dex as dex__0_ FROM ProjectParameters parmarr0_ WHERE parmarr0_.ProjectID=@p0
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened IDataReader, open IDataReaders: 1
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - result set contains (possibly empty) collection: [NHibernateCETest.ProjectInclude.ParmArr#119]
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - uninitialized collection: initializing
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - processing result set
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - done processing result set (0 rows)
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Driver.NHybridDataReader [(null)] <(null)> - running NHybridDataReader.Dispose()
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDataReader, open IDataReaders :0
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDbCommand, open IDbCommands: 0
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - 1 collections were found in result set
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - collection fully initialized: [NHibernateCETest.ProjectInclude.ParmArr#119]
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - 1 collections initialized
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - done loading collection
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - collection initialized
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - done materializing entity [NHibernateCETest.ProjectInclude#119]
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - initializing non-lazy collections
2007-01-09 17:29:07,612 [TestRunnerThread] DEBUG NHibernate.Loader.Loader [(null)] <(null)> - done entity load


Code Files:
Code:
using System;
using NHibernate.Mapping.Attributes;

namespace NHibernateCETest
{
   [Class(Table="ProjectParameters")]
   public class ProjectParameter
   {
      public int parmID = 0;
      
      public String val;
      public String name;
      
      public ProjectParameter() { }
      public ProjectParameter(String nam, String val)
      {
         name = nam;
         this.val = val;
      }
   }
}


Code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

using NHibernate.Mapping.Attributes;
using Iesi.Collections;

namespace NHibernateCETest
{
   public class ProjectInclude
   {
      public Dictionary<String, String> parms = new Dictionary<String, String>();

      public int IncludeID = 0;

      public String this[String name]
      {
         set { parms[name] = value; }
      }

      public virtual System.Collections.IList ParmArr
      {
         get
         {
            System.Collections.ArrayList al = new System.Collections.ArrayList();
            foreach (String str in parms.Keys)
            {
               al.Add(new ProjectParameter(str, parms[str]));
            }
            return al;
         }
         set
         {
            foreach (ProjectParameter p in value)
            {
               this[p.name] = p.val;
            }
         }
      }
   }
}



Problems with Session and transaction handling?
The problem I'm having is that the ProjectInclude is not persisting the ParmArr Collection. I've tried a few dozen odd variations, and I'm certain that there is something I'm doing wrong.

Ultimately I'm trying to avoid the back reference required for a one-to-many relationship.

Can anyone see anything obviously wrong?

The ProjectInclude table consists of a Single Identity, ID, the ProjectParameters table has a ParameterID Identity, Name varchar, Val varchar, dex int, and ProjectID int.

Of Possible Note: Manually inserting the relevant data into the database results in it being read in, the only problem seems to be the first insertion.

Any thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 10, 2007 12:30 am 
Senior
Senior

Joined: Mon Aug 21, 2006 9:18 am
Posts: 179
inverse=true doesn't work on lists or maps...only bags and sets. That may be causing the problem.

Maybe try removing the inverse=true flag and see if that fixes it.

Cheers,
MIKE

_________________
If this helped...please remember to rate it!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 10, 2007 10:16 am 
Newbie

Joined: Tue Jan 09, 2007 7:38 pm
Posts: 5
Sadly that was one of the many variations that I've tried. No joy, doesn't work...

The log file looks pretty much the same (This portion comes from only the insertion operation)

Code:
2007-01-10 08:16:44,102 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - unsaved-value: 0
2007-01-10 08:16:44,134 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - SaveOrUpdate() unsaved instance
2007-01-10 08:16:44,134 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - saving [NHibernateCETest.ProjectInclude#<null>]
2007-01-10 08:16:44,149 [TestRunnerThread] DEBUG NHibernate.Impl.SessionImpl [(null)] <(null)> - executing insertions
2007-01-10 08:16:44,149 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - processing cascades for: NHibernateCETest.ProjectInclude
2007-01-10 08:16:44,149 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - done processing cascades for: NHibernateCETest.ProjectInclude
2007-01-10 08:16:44,165 [TestRunnerThread] DEBUG NHibernate.Impl.WrapVisitor [(null)] <(null)> - Wrapped collection in role: NHibernateCETest.ProjectInclude.ParmArr
2007-01-10 08:16:44,165 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Inserting entity: NHibernateCETest.ProjectInclude (native id)
2007-01-10 08:16:44,180 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened new IDbCommand, open IDbCommands: 1
2007-01-10 08:16:44,180 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Building an IDbCommand object for the SqlString: INSERT INTO ProjectIncludes DEFAULT VALUES; select SCOPE_IDENTITY()
2007-01-10 08:16:44,180 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Dehydrating entity: [NHibernateCETest.ProjectInclude#<null>]
2007-01-10 08:16:44,196 [TestRunnerThread] DEBUG NHibernate.Connection.DriverConnectionProvider [(null)] <(null)> - Obtaining IDbConnection from Driver
2007-01-10 08:16:44,524 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Opened IDataReader, open IDataReaders: 1
2007-01-10 08:16:44,555 [TestRunnerThread] DEBUG NHibernate.Persister.Entity.AbstractEntityPersister [(null)] <(null)> - Natively generated identity: 123
2007-01-10 08:16:44,555 [TestRunnerThread] DEBUG NHibernate.Driver.NHybridDataReader [(null)] <(null)> - running NHybridDataReader.Dispose()
2007-01-10 08:16:44,555 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDataReader, open IDataReaders :0
2007-01-10 08:16:44,555 [TestRunnerThread] DEBUG NHibernate.Impl.BatcherImpl [(null)] <(null)> - Closed IDbCommand, open IDbCommands: 0
2007-01-10 08:16:44,571 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - processing cascades for: NHibernateCETest.ProjectInclude
2007-01-10 08:16:44,571 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - cascading to collection: NHibernateCETest.ProjectInclude.ParmArr
2007-01-10 08:16:44,571 [TestRunnerThread] DEBUG NHibernate.Engine.Cascades [(null)] <(null)> - done processing cascades for: NHibernateCETest.ProjectInclude


New mapping file:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
   <class name="NHibernateCETest.ProjectInclude, NHibernateCETest" table="ProjectIncludes" lazy="false">
      <id name="IncludeID" column="ID" unsaved-value="0" access="field">
         <generator class="native" />
      </id>
      <list name="ParmArr" cascade="all" table="ProjectParameters" lazy="false">
         <key column="ProjectID" />
         <index column="dex" />
         <composite-element class="NHibernateCETest.ProjectParameter, NHibernateCETest">
            <property name="name" column="Name" access="field"/>
            <property name="val" column="Val" access="field"/>
         </composite-element>
      </list>
   </class>
</hibernate-mapping>


Any other thoughts?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 10, 2007 10:57 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
The session isn't being flushed anywhere. Use transactions or call session.Flush() yourself. NHibernate tries to delay as many updates as possible and only perform them during Flush().


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 10, 2007 11:35 am 
Newbie

Joined: Tue Jan 09, 2007 7:38 pm
Posts: 5
Thank you, that fixed it.


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