-->
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.  [ 6 posts ] 
Author Message
 Post subject: Abstract joined-subclass still generates create table
PostPosted: Thu Feb 01, 2007 7:42 pm 
Newbie

Joined: Thu Feb 01, 2007 7:29 pm
Posts: 5
Even though "abstract" is set to "true" DDL is generated to create a table for an abstract class mapping. The Java class is marked as abstract and there are 2 concrete classes also mapped (one is below). Each Java class (abstract and the 2 concrete) have separate mapping files.

Also why do I have to

I'm using org.hibernate.tool.hbm2ddl.SchemaExportTask to generate the DDL.

Thx for any help you can give,

Dan

<!-- code from abstract mapping file -->
<joined-subclass
name="AbstractRepositoryFeature"
extends="RepositoryObject"
abstract="true">

<key column="ID" />

<property
name="index"
column="NDX"
type="integer"
not-null="true">
</property>

<property
name="lowerBound"
column="LOWER_BOUND"
type="integer"
not-null="false">
</property>

<property
name="upperBound"
column="UPPER_BOUND"
type="integer"
not-null="false">
</property>

<many-to-one
name="datatype"
class="RepositoryObject"
column="DATATYPE_ID">
</many-to-one>
</joined-subclass>

<!-- code from concrete class mapping file -->
<joined-subclass
table="MMR_REFS"
extends="AbstractRepositoryFeature"
name="RepositoryReference">

<key column="ID" />

<property
name="containment"
column="IS_CONTAINMENT"
type="boolean"
not-null="false">
</property>

<many-to-one
name="opposite"
class="RepositoryObject"
foreign-key="OPPOSITE_ID">
</many-to-one>
</joined-subclass>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 8:37 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
abstract="true" does not affect DDL: if it did, table-per-class-hierarchy mixed with table-per-subclass wouldn't work. If the abstract superclass genuinely has no dedicated table, then don't give it a table="tablename" attrbiute. That'll prevent DDL generation for it.

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject: Create Table DDL Generated When No Table Tag and Abstract
PostPosted: Fri Feb 02, 2007 9:08 am 
Newbie

Joined: Thu Feb 01, 2007 7:29 pm
Posts: 5
tenwit wrote:
abstract="true" does not affect DDL: if it did, table-per-class-hierarchy mixed with table-per-subclass wouldn't work. If the abstract superclass genuinely has no dedicated table, then don't give it a table="tablename" attrbiute. That'll prevent DDL generation for it.


Thx for your quick response. There is no "table" tag on the abstract class. Please note the first mapping file below does NOT have that tag. Only the joined-subclass mapping file that "extend" the abstract joined-subclass does.

<!-- code from abstract mapping file -->
<joined-subclass
name="AbstractRepositoryFeature"
extends="RepositoryObject"
abstract="true">

<key column="ID" />

<property
name="index"
column="NDX"
type="integer"
not-null="true">
</property>

<property
name="lowerBound"
column="LOWER_BOUND"
type="integer"
not-null="false">
</property>

<property
name="upperBound"
column="UPPER_BOUND"
type="integer"
not-null="false">
</property>

<many-to-one
name="datatype"
class="RepositoryObject"
column="DATATYPE_ID">
</many-to-one>
</joined-subclass>

<!-- code from concrete class mapping file -->
<joined-subclass
table="MMR_REFS"
extends="AbstractRepositoryFeature"
name="RepositoryReference">

<key column="ID" />

<property
name="containment"
column="IS_CONTAINMENT"
type="boolean"
not-null="false">
</property>

<many-to-one
name="opposite"
class="RepositoryObject"
foreign-key="OPPOSITE_ID">
</many-to-one>
</joined-subclass>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 04, 2007 4:03 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
It's the <class> mapping that I'm talking about, not any of the <joined-subclass> mappings. What does that look like?

_________________
Code tags are your friend. Know them and use them.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 5:21 pm 
Newbie

Joined: Thu Feb 01, 2007 7:29 pm
Posts: 5
Okay, we've changed things a little bit from the first post. Let me first fully explain what we're trying to do. We have a set of concrete objects, RO, that we wish to be mapped to a table. There is also a abstract subclass of RO called ARF, for which there are 2 concrete sublcasses (and thus tables), RR and RA. We want the concrete tables for RR and RA to each contain the columns defined by ARF, but not those defined by RO. In other words, we want to join with RO, but union with ARF. Here are the latest mappings we have (which produce the unwanted "ARF" table):

<class
name="RO"
table="RO">

<id
name="id"
type="long"
column="ID">
<generator class="increment"></generator>
</id>

<property
name="A"
column="A"
type="string"
not-null="false"
length="64">
</property>
</class>

<joined-subclass
name="ARF"
extends="RO"
abstract="true">

<key column="id" />

<property
name="B"
column="B"
type="integer"
not-null="true">
</property>
</joined-subclass>

<union-subclass
table="RR"
extends="ARF"
name="RR">

<property
name="C"
column="C"
type="boolean"
not-null="false">
</property>
</union-subclass>

<union-subclass
table="RA"
extends="ARF"
name="RA">

<property
name="D"
column="D"
type="boolean"
not-null="false">
</property>
</union-subclass>

The rest of the resulting DDL is exactly what we want; the RR and RA tables contain the columns defined in their own and the ARF mappings, but not the RO mapping (except the ID, of course). The only problem seems to be a table for the ARF mapping also gets generated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 4:32 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Working in abbreviations and acronyms gives me headaches. It will also earn you the undying hatred of whoever has to maintain your mappings and schema after you've found another job.

I'm not sure that hiberante supports abstract subclasses of concrete classes. I've never tried to implement that. Assuming that your assertions are correct, and all of these relations are "is-a" and "kind-of", but not "is-a-role", then I'd probably implement this as an abstract superclass (no table) that has three concrete subclasses: the one that stored in RO and not any other table; the one that is stored in RO and in RR; and the one that is stored in RO and RA.

Perhaps you should consider delegation instead of inheritance, as these relationship seem to be to be anything but self-documenting.

_________________
Code tags are your friend. Know them and use them.


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