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: Need a little advice on proper mapping
PostPosted: Mon Sep 24, 2007 5:56 pm 
Newbie

Joined: Fri Sep 14, 2007 8:51 pm
Posts: 12
Location: North Carolina
Hibernate version: 2.2

Ok. So I tried what I said in:
http://forum.hibernate.org/viewtopic.php?t=979761

This SkillInventory object is not so hot. There is no way to bind a DataGrid Column through a complex object to one of its properties (example: SkillInventory.Skill.Name or SkillInventory.Person.FirstName) Well, at least that I could find.

How do I create a SkillInventory object that is more useful? How do Hibernate/NHibernate developers normally handle this issue?

db schema and mapping file below:

Thanks,
kellygreer1

Code:
                       
____________________             
| SkillInventory     |   
|____________________| 
| id (int)*          | 
| people_id (int)    |
| skill_id (int)     |
| strength_id (int)  |
|____________________|
___________________________             
| People                    |
|___________________________| 
| id (int)*                 |   
| first_name (varchar(24))  |
| last_name (varchar(24))   |
|___________________________|
___________________________             
| Skill                     | 
|___________________________|   
| id (int)*                 |         
| skill_name (varchar(50))  |
|___________________________|
___________________________             
| Strength                  |   
|___________________________|     
| id (int)*                 |   
| description (varchar(30)) |
|___________________________|


Mapping File:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                            namespace="Doa.Domain.Entities" assembly="Doa.Domain">
  <class name="SkillInventory" table="SkillInventory">
      <id name="Id" column="id" type="Int32" unsaved-value="-1"
            access="field.camelcase-underscore">
         <generator class="native" />
      </id>
    <many-to-one name="Person" class="Person" column="people_id" cascade="all" />
    <many-to-one name="Skill" class="Skill" column="skill_id" cascade="all" />
    <many-to-one name="Strength" class="Strength" column="strength_id" cascade="all" />
  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 24, 2007 6:36 pm 
Newbie

Joined: Mon Sep 24, 2007 4:22 pm
Posts: 6
Location: Ukraine, Kharkiv
1. You can create helper property:

Code:
public string SkillName {
get {
   return Skill.Name;
}
}


2. You can manually bind properties with dot-notation on a data bind event through reflection (I did it for DevExpress). But it seems like this already works with DataGrid if you use DataSet as data source, so you can try use dot notation for classes


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 25, 2007 7:14 am 
Newbie

Joined: Fri Sep 14, 2007 8:51 pm
Posts: 12
Location: North Carolina
I tried the #1 method last night. It works ok I guess. It allows me to databind to a grid.

Not sure what you mean in #2. I was not able to bind a column to
SkillInventory.Person.FirstName (Person.FirstName) or SkillInventory.Skill.SkillName (Skill.SkillName). Is there another syntax?

Thanks,
kellygreer1


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 25, 2007 7:31 am 
Newbie

Joined: Mon Sep 24, 2007 4:22 pm
Posts: 6
Location: Ukraine, Kharkiv
Looks like "SkillInventory.Person.FirstName" works only for DataSets. I have looked to DataGrid interface and haven't found any appropriate event to override :(

For example I use DevExpress and overrided a CustomShowText event. I check Field property and if it contains a dot, i try to parse it and find child properties through reflection.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 25, 2007 4:56 pm 
Newbie

Joined: Fri Sep 14, 2007 8:51 pm
Posts: 12
Location: North Carolina
When you say DevExpress or you talking about a CodeRush application or a DevExpress DataGrid? I'll assume your talking about the grid.

I guess I'll stick with the "Helper" properties. Went to a bookstore at lunch and looked at 3 Hibernate books. None seemed to really tackle the topic specifically. Going to send a note to the NHibernate book guys. With .NET DataBinding this seems like a worth while topic.

Thanks for your help, tihobrazov
kellygreer1


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.