-->
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: Two tables & three mapping classes inherits from each ot
PostPosted: Mon May 01, 2006 12:46 am 
Newbie

Joined: Fri Apr 28, 2006 6:50 am
Posts: 1
Hi, I am new in using NHibernate. I have tried my best to search the forum for all kind of information that might help, but I just cant find one that solve my problem.

I have a modelling problem, in that, I have 2 tables e.g Table A and B, and 3 classes : A, B, C. Class A is the parent of class B, class B is the parent of class C. Class A is mapped to table A, while class B and C are mapped to the one table i.e table B.

The reason why table B is seperated into 2 classes is because sometimes we need to insert only part of the data (which is mapped by class B). And another time, we may need to insert all the data (mapped in class C, which inherits from Class B).

Another reason is because an application is already developed with that structure, so we are trying to minimise re-coding by modifying the behaviour set in NHibernate.

I have attached the code for your viewing. With the current structure, the problem occurs when trying to insert using class C, because after inserting into table B, class B is also doing the insert into table B using the same id, and Oracle throws duplicate error.

Can anyone tell me how i can make this work?
All help is very much appreciated.

Btw, I am using NHibernate version 1.0


Mapping documents:
The parent class :

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name ="ServerApplication.Expedient.Transaction.Register, ServerApplication"
table="Register" >
<id name="RegId" type ="String" length ="40">
<generator class="uuid.hex" ></generator>
</id>
<property name="RegDocDate" type="DateTime" />
<property name="RegAnnoDate" type="DateTime" />
<property name="RegUser" type="String" length ="9"/>
<property name="RegOrg" type="String" length="3"/>
<property name="RegAtasNama" type="String" length="1"/>

<many-to-one name="TipeLink"
class ="ServerApplication.Core.Master.TipeRegister, ServerApplication"
column ="RegTipe" />
<many-to-one name="KodeLink"
class ="ServerApplication.Core.Master.KodeRegister, ServerApplication"
column ="RegKode" />

<many-to-one name="ProsedurLink"
class ="ServerApplication.Expedient.BerkasDok.Prosedur, ServerApplication"
column ="ProsedurCode" />

<many-to-one name="BerkasLink"
class ="ServerApplication.Expedient.BerkasDok.Berkas, ServerApplication"
column ="BerkasId" />

<many-to-one name="BerkasLockLink"
class ="ServerApplication.Expedient.BerkasDok.Berkas, ServerApplication"
column ="BerkasIdLock" />

<many-to-one name="RegOfficeLink"
class ="ServerApplication.Role.Office, ServerApplication"
column ="OfficeId" />

<!--
<property name="EmployeeNipLink" column ="EmployeeNip" type="String" length ="32"/>
-->
<many-to-one name="RegEmployeeLink"
class ="ServerApplication.Role.Employee, ServerApplication"
column ="EmployeeNip" />
</class>
</hibernate-mapping>

Child class :
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<joined-subclass
name="ServerApplication.Expedient.Transaction.RegHAT,ServerApplication"
extends ="ServerApplication.Expedient.Transaction.Register,ServerApplication"
table="REGHAT" >
<key column="RegId"/>

<many-to-one name="DesaLink"
column="DESAID"
class="ServerApplication.Core.Administrative.Desa, ServerApplication" />
<many-to-one name="TipeHakLink"
column="TIPEHAKID"
class="ServerApplication.Core.Master.TipeHak, ServerApplication" />
<property column="NOMOR" type="String" name="Nomor" length="15" />
<property column="FlagDok" type="String" name="TipeDok" length="1" />

</joined-subclass>
</hibernate-mapping>

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<joined-subclass
name="ServerApplication.Core.Products.DokHAT,ServerApplication"
extends ="ServerApplication.Expedient.Transaction.RegHAT,ServerApplication"
table="REGHAT">
<key column="RegId" />
<property column="HATDATE" type="DateTime" name="HATDate" />
<property column="HATEXPIRE" type="DateTime" name="HATExpire" />
<many-to-one name="DokHATEmployeeLink" column="EMPLOYEENIP"
class="ServerApplication.Role.Employee,ServerApplication" />
<property column="HATSTATUS" type="String" name="HATStatus" length="1" />
<property column="HATATASNAMA" type="String" name="HATAtasNama" length="1" />
<property column="HATORIGIN" type="String" name="HATOrigin" length="3" />
<property column="PENUNJUK" type="String" name="Penunjuk" length="1000" />
<many-to-one name="AsalPersilLink" column="ASALPERSILID"
class="ServerApplication.Core.Products.AsalPersil,ServerApplication" />
<property column="ASALPERSILREMARK" type="String" name="AsalPersilRemark" length="1000" />
<property column="USERENTRI" type="String" name="UserEntri" length="9" />
<property column="TANGGALENTRI" type="DateTime" name="TanggalEntri" />
</joined-subclass>
</hibernate-mapping>


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.