Hi all,
I am using NHibernate 2.1, .Net 3.5, Oracle 9i and LinFu as proxy.
I follow the very good tutorial on dynamic mapping on this blog
http://ayende.com/Blog/archive/2008/05/ ... rnate.aspxEverything is ok with the configuration and sessionFactory. But i have a bug on loading the
dynamic component. Here is my class :
Code:
class NodeReference
{
public virtual int Id {get; set;}
public virtual Hashtable Properties { get; set; }
}
Here is the mapping :
Code:
<class name="NodeReference" table="PROJECT" >
<id name="ID" column="ID">
<generator class="hilo" />
</id>
<dynamic-component name="Properties">
</dynamic-component>
</class>
Here is my table :
PROJECT:
ID NUMBER,
NAME VARCHAR2,
FULLNAME VARCHAR2,
BEGIN_DATE DATE,
END_DATE DATE
I have got one row in the table that contains a project :
ID NAME FULLNAME BEGIN_DATE END_DATE
0 MyProject MyFULLProject 01/01/10 05/01/10
When i use "nodeRef = session.Get", the SQL request looks like :
Code:
SELECT ID, NAME, BEGIN_DATE FROM PROJECT WHERE ID=;
And the nodeRef object loaded contains :
Code:
Id = 0
nodeRef.Properties["NAME"] : MyProject
nodeRef.Properties["FULLNAME"] : MyProject
nodeRef.Properties["BEGIN_DATE"] : 01/01/10
nodeRef.Properties["END_DATE"] : 01/01/10
As you can see, on loading, NHibernate fill all the properties of the same type with the first column of the specific type.
I tried to use Castle but it's the same.
So to fix the bug, i use the SetProjection, to get the columns values, and re-inject the value in the object like this :
Code:
nodeRef = session.get(0)
Object[] objRef = session.CreateCriteria(NodeReference)
.SetProjection("Properties.NAME")
etc.
then
nodeRef.Properties["NAME"] = objRef[i];
and the associated request select all columns :
Code:
SELECT ID, NAME, FULLNAME, BEGIN_DATE, END_DATE FROM PROJET;
And the nodeRef object contains :
Code:
Id = 0
nodeRef.Properties["NAME"] : MyProject
nodeRef.Properties["FULLNAME"] : MyFULLProject
nodeRef.Properties["BEGIN_DATE"] : 01/01/10
nodeRef.Properties["END_DATE"] : 05/01/10
AND when i save a new nodeRef, everything is ok, all columns are saved.
So, did i do something wrong, or is it a known bug ?
Any help is welcome.
Regards.