-->
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: Generated ddl causing problems with subclass?
PostPosted: Thu Jan 26, 2006 3:17 pm 
Newbie

Joined: Thu Jan 26, 2006 2:19 pm
Posts: 4
I'm trying to represent a simple class heirarchy of:

Expense
-- LeaseExpense
-- TennantExpense

In this class heirarchy, the subclasses are used to determine which object the expense is applied to. To represent this I used the following code:

Code:
<class name="Expense" table="expenses">
...
   <discriminator column="expenseType" type="string"/>
...
   <subclass name="LeaseExpense" discriminator-value="lease">
      <many-to-one name="appliedTo" column="lease" class="Lease"/>
   </subclass>
      
   <subclass name="TennantExpense" discriminator-value="tennant">
      <many-to-one name="appliedTo" column="tennant" class="Tennant"/>
   </subclass>
      
</class>


Everything looks straightforward, but when I create the DDL through hibernate I get the following interesting constraint:

Code:
alter table expenses
    add constraint FK8CA4431B76C5718A
    foreign key (tennant)
    references tennants;
alter table expenses
    add constraint FK8CA4431BD1F8DB8E
    foreign key (lease)
    references tennants;


You'll notice that the second constraint states that the "lease" column references the "tennants" table. This causes a constraint violation when I attempt to save a LeaseExpense.

If I rewrite this constraint by hand to reference the "leases" table then I can successfully save an Expense. But the fact that Hibernate is generating the wrong constraint is worrying me. It makes me think I'm doing something fundamentally wrong.

The questions I have are:
    Am I doing something obviously wrong in the mapping?
    Is there an easier way to do what I'm attempting?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 2:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
which version?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 11:22 am 
Newbie

Joined: Thu Jan 26, 2006 2:19 pm
Posts: 4
I'm using Hibernate 3.0.5

After playing with this yesterday I found that if I modify the ddl by hand so that the constraints look like:

Code:
alter table expenses
    add constraint FK8CA4431B76C5718A
    foreign key (tennant)
    references tennants;
alter table expenses
    add constraint FK8CA4431BD1F8DB8E
    foreign key (lease)
    references leases;


Then it seems to work fine. So it could just be the exported DDL that is incorrect. Still, there should be some way to get it to generate the correct constraints.


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.