-->
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.  [ 4 posts ] 
Author Message
 Post subject: Complex mapping
PostPosted: Sun Nov 20, 2005 11:19 am 
Hi

I try to make a basic item system, i have one table where are stored all items template and another where are stored instancied item template (called owned objects).

It look like that :

Image


To be clear i want in my database two tables,

The first table is called Object, this table is used to store the generalisation with a table-per-class-hierarchy. This table stores all templates (objects, weapon and armor).

The second table is called OwnedObject and must store all owned objects (each owned object include some extra fields and one template).

The database structure look like:

Image


A classic mapping file like that persist the template stored inside the owned object in the table Object but in my case it is not good because players must be able to change thir item condition, inventorySlot or even the damage of their item without change anything in the template table.

Classic mapping, not good in my case :
Code:
<class name="App.Object" table="`Object`">
   <id name="ObjectID" column="`ObjectID`">
      <generator class="native" />
   </id>
   <property name="Name"/>
   <property name="Condition"/>
   <subclass name="App.Weapon">
      <property name="Damage" column="Damage" />
   </subclass>
   <subclass name="App.Armor">
      <property name="Absorbtion" column="Absorbtion" />
   </subclass>
</class>

<class name="App.OwnedObject" table="`OwnedObject`">
   <id name="OwnedObjectID" column="`OwnedObjectID`">
      <generator class="native" />
   </id>
   <property name="InventorySlot"/>
   <property name="CrafterName"/>
   <many-to-one name="Object" unique="true" class="App.Object"/>
</class>


With this mapping the database table OwnedObject does not store the template (Object) but only its primary key.

To resume my problem is the many-to-one relation not persist the template in the OwnedObject table, it just make a link to the Object table. Does it exist a way to solve my problem with a many-to-one, or does the <component> tag can be used with a class witch is itself used to make a generalisation by another class.

Thanks for your help and sorry for my bad english.


Top
  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 1:26 pm 
In the spirit i would like to do a such mapping (but it does not work) :

Code:
<class name="App.Object, App" table="`Object`">
   <id name="ObjectID" column="`ObjectID`">
      <generator class="native" />
   </id>
   <discriminator column="Type" />
   <property name="Name"/>
   <property name="Condition"/>
   <subclass name="App.Weapon, App">
      <property name="Damage" column="Damage" />
   </subclass>
   <subclass name="App.Armor, App">
      <property name="Absorbtion" column="Absorbtion" />
   </subclass>
</class>

<class name="App.OwnedObject, App" table="`OwnedObject`">
   <id name="OwnedObjectID" column="`OwnedObjectID`">
      <generator class="native" />
   </id>
   <property name="InventorySlot"/>
   <component name="Object" class="App.Object, App">
      <discriminator column="Type" />
      <property name="Name"/>
      <subclass name="App.Weapon, App">
         <property name="Damage" column="Damage" />
      </subclass>
      <subclass name="App.Armor, App">
         <property name="Absorbtion" column="Absorbtion" />
      </subclass>
   </component>
</class>


I really need help, i am working on it for 4 hours :roll:


Top
  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 8:49 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I don't understand the mapping of OwnedObject... Why do you use component?
Your relation look more like a one-to-many...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 21, 2005 4:26 pm 
Yes, in a normal case it will be a simple many-to-one but my problem is i need to persist all proprieties of template in one table and all proprieties of instance in another.

Here is what i must do :
Code:
Weapon myWeaponTemplate = Database.SelectObject(typeof(Weapon),  Expression.Eq("Damage", 1)); // the syntax line is not important, just understand its meaning

// myWeaponTemplate is a template with Damage=1 persisted in the table Object

OwnedObject myCustomWeapon = new OwnedObject();
myCustomWeapon.CrafterName = "toto";
myCustomWeapon.Template = myWeaponTemplate;
myCustomWeapon.Template.Damage = 2;

Database.SaveObject(myCustomWeapon);

// here myCustomWeapon is saved in the table OwnedObject and its propriety damage too. I dont want to change the db row of myWeaponTemplate but i want to save my whole OwnedObject class in its own table

// then if i do
OwnedObject myCustomWeapon = Database.SelectObject(typeof(OwnedObject),  Expression.Eq("CrafterName ", "toto"));
// i retrive my last owned object with its propriety Damage = 2

//but if i made
Database.SelectObject(typeof(Weapon),  Expression.Eq("Damage", 1));
// i retrive my last template with its propriety Damage = 1


The mapping with component explain well what i want to do, request a object from one table then save it in another table as a component of a another class.


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