-->
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: many-to-one relation in a lazy way
PostPosted: Mon Jun 05, 2006 4:47 pm 
Beginner
Beginner

Joined: Fri May 12, 2006 10:48 am
Posts: 33
I asked before about loading many-to-one relation in a lazy way. I should add to my mapping files “Lazy=true” in the class definition and then declare the class properties as Overridable.
Now I’m having the following problem. I have these classes.

<class name=" Empresa " table="Empresas" lazy="true">
<id name="Id" type="Int32" unsaved-value="0">
<column name="idEmpresa" sql-type="int" not-null="true" unique="true" />
<generator class="native" />
</id>
<property name="Codigo" type="String">
<column name="codEmpresa" length="4" sql-type="char" not-null="true" unique="true" />
</property>
<property name="Descripcion" type="String">
<column name="Descripcion" length="60" sql-type="char" not-null="true"/>
</property>
<many-to-one name="Sector" class="Sector">
<column name="IdSector" sql-type="int" not-null="false"/>
</many-to-one>
</class>

And

<class name="Sector " table="Sectores" lazy="true">
<id name="Id" type="Int32" unsaved-value="0">
<column name="IdSector" sql-type="int" not-null="true" unique="true" />
<generator class="native" />
</id>
<property name="CodSector" type="String">
<column name="codSector" length="3" sql-type="char" not-null="true"/>
</property>
<property name="Descripcion" type="String">
<column name="Descripcion" length="60" sql-type="varchar" not-null="true"/>
</property>
</class>

When I load first a list with Empresas, first a “Select” on Empresas table is done and then, several selects on Sector table are done (one for each Object Empresa that I show in the list), all this works fine but when I load a ComboBox with Sectores and a new Select on Sectores table is done, the new Sector objects (that weren’t loaded in the Empresas List) don’t show their Description in the ComboBox, they show “Sector” (their namespace) instead.
Could anybody help me?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 05, 2006 5:47 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
please post the code where you are populating the ComboBox in both instances. i am guessing you are populating the ComboBox from the Empresa.Sector.Description property (which youd give you the text of the description) but when you load all of the Sectores you should be using Sector.Description....

-devon


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 06, 2006 11:44 am 
Beginner
Beginner

Joined: Fri May 12, 2006 10:48 am
Posts: 33
Hi Devonl, thanks for your reply.
First I load a DataGrid with a list of Empresas where I show Codigo, Descripcion and Sector in the DataGrid, the code that I use to populate the DataGrid is :

ugEmpresas.DataSource = EmpresaBZ.List(miSession)

List method in the EmpresaBz class just does the following

Public Function List(ByVal session As ISession) As IList
Dim query As String
query = "from Empresa order by Descripcion"
List = ObjectBZ.Find(session, query)
End Function

Find method in the ObjectBZ class calls Nhibernate session Find method as it’s showed below:

Public Function Find(ByVal session As ISession, ByVal query As String) As IList
Find = session.Find(query)
End Function

After I populated the Datagrid, I load a Combobox with Sectores like this:

Private Sub CargoComboSector()
With Me.cboSector
.DataSource = SectorBZ.List(miSession)
.DisplayData = "Descripcion"
.ValueMember = "Id"
End With
End Sub

And the List method in the SectorBZ class does the following query

Public Function List(ByVal session As ISession) As IList
Dim query As String
query = "from Sector order by Descripcion"
List = ObjectBZ.Find(session, query)
End Function


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.