-->
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: Bug on loading dynamic component using dynamic mapping
PostPosted: Wed Jun 09, 2010 5:15 am 
Newbie

Joined: Wed Jun 09, 2010 5:11 am
Posts: 1
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.aspx
Everything 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.


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.