-->
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.  [ 2 posts ] 
Author Message
 Post subject: Odd inheritance mapping required
PostPosted: Wed Jun 29, 2005 8:15 am 
Newbie

Joined: Wed Jun 29, 2005 8:01 am
Posts: 2
Hibernate version:
3.0.5


Hi,

I am trying to map a subclass but none of the strategies in the documentation seem to match my need. Consider:

A class OrgUnit, with sub-classes Company and Outlet.

In our database this is represented by:

Table ORG_UNIT:
ORGU_ID bigint not null,
LCOUNT bigint not null,
ORGU_CODE varchar(255),
COMP_ID bigint,
OUTL_ID bigint,
ORGT_TYPE_ID bigint not null,
ORGU_DEF_LEGT_ID bigint not null,
primary key (ORGU_ID),
unique (ORGU_CODE),
unique (ORGU_DEF_LEGT_ID),
foreign key (COMP_ID) references COMPANY,
foreign key (OUTL_ID) references OUTLET,
foreign key (ORGT_TYPE_ID) references ORG_TYPE

Table COMPANY:
COMP_ID bigint not null,
LCOUNT bigint not null,
-- other cols
primary key (COMP_ID)

Table OUTLET:
OUTL_ID bigint not null,
LCOUNT bigint not null,
-- other cols
primary key (COMP_ID)

Table ORG_TYPE:
ORGT_TYPE_ID bigint not null,
ORGT_TYPE_NAME varchar(60) not null,
ORGT_TYPE_CONST bigint not null,
LCOUNT bigint not null,
-- other cols
primary key (ORGT_TYPE_ID)

so, if i get an ORG_UNIT with a COMP_ID not null and a ORGT_TYPE_ID with an associated ORGT_TYPE_CONST of 1 then i want a Company coming back from a query. Similarly if it has an OUTL_ID, and ORGT_TYPE_CONST of 2, then I want an Outlet. If neither I just want a raw OrgUnit.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 8:16 am 
Newbie

Joined: Wed Jun 29, 2005 8:01 am
Posts: 2
forgot my mapping:

<hibernate-mapping>
<class name="pcms.model.OrgUnit" table="ORG_UNIT" optimistic-lock="version" >
<id name="id" type="long" column="ORGU_ID">
<!-- <generator class="sequence">-->
<!-- <param name="sequence">ORG_UNIT_SEQ</param>-->
<!-- </generator>-->
<generator class="increment"/>
</id>
<version name="lcount" type="long" column="LCOUNT"/>
<property name="code" column="ORGU_CODE" unique="true" />
<property name="companyId" column="COMP_ID" access="field" />
<many-to-one name="defaultCurrency" class="pcms.model.Currency" column="ORGU_DEF_LEGT_ID" unique="true" not-null="true" />

<joined-subclass name="pcms.model.Company" table="COMPANY" >
<key column="COMP_ID"/>
</joined-subclass>
</class>


</hibernate-mapping>

but this doesn't do the job, it expects that company has the foreign key to orgunit not the other way round. and it certainly doesn't check org_type.


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