-->
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: Duplicate columns in SchemaExport w/ map to union-subclass
PostPosted: Wed Feb 28, 2007 6:42 pm 
Newbie

Joined: Wed Feb 28, 2007 5:36 pm
Posts: 2
Hi everyone,

First, thanks for Hibernate - it's a marvelous tool. Now my question. I am using Hibernate version 3.2 and I believe I have discovered an issue with SchemaExport. Specifically, it appears to produce duplicate columns when a collection refers to a union-subclass.

Here are two example mapping documents. The first document describes a class Foo that refers to a class Baz (in the second mapping document) which extends (via union-subclass) a class Bar (also in the second mapping document).

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
          PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0/EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="p.Foo">
      <id name="id" type="int" column="id"/>   
      <map name="bazMap" cascade="delete-orphan" lazy="false">
         <key column="fooId"/>
         <index column="name" type="string"/>
         <one-to-many class="p.Baz"/>
      </map>
   </class>
</hibernate-mapping>


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
          PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0/EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="p.Bar" abstract="true">
      <id name="id" type="int" column="id"/>
      <many-to-one name="foo" column="fooId" class="p.Foo"/>
      <property name="name" type="string"/>
      <union-subclass name="p.Baz" table="baz"/>
   </class>
</hibernate-mapping>


When I run SchemaExport against my database, MySQL 5, it produces the following SQL statement (among others):

Code:
create table baz (id integer not null, fooId integer, name varchar(255), fooId integer, name varchar(255), primary key (id)) type=InnoDB


This causes an error because the "fooId" and "name" columns are repeated.

Now, If I modify the first mapping document so that the <one-to-many> element refers to the class "p.Bar", the superclass of p.Baz, then the (valid) SQL statement that is generated looks like this.

Code:
create table baz (id integer not null, fooId integer, name varchar(255), primary key (id)) type=InnoDB


Note that the duplicates columns are gone. It's as if the fields in the p.Bar superclass are being discovered twice when the map refers to the p.Baz subclass.

Any suggestions would be greatly appreciated.

Thanks,
Jeff


Top
 Profile  
 
 Post subject: Check this
PostPosted: Thu Mar 01, 2007 4:57 am 
Newbie

Joined: Mon Feb 19, 2007 12:54 am
Posts: 16
Location: banglore, india
Union-Subclass To map only the concrete classes of an inheritance hierarchy to tables, (the table-per-concrete-class strategy) where each table defines all persistent state of the class, including inherited state.

This is from hibernate reference.

When u use union-subclass it tries to create table with all the properties in that class with corresponding columns.
In your hbms fooId,name columns are present in both the columns. So it tries to create duplicate columns.

_________________
Banglore Developer


Top
 Profile  
 
 Post subject: Re: Check this
PostPosted: Thu Mar 01, 2007 11:46 am 
Newbie

Joined: Wed Feb 28, 2007 5:36 pm
Posts: 2
Ok, I think I see why SchemaExport is doing this, but it doesn't seem correct to me.

When SchemaExport is deciding what columns need to be in the p.Baz table, it discovers that p.Foo requires name and fooId columns to serve the map. It also discovers that p.Baz inherits name and fooId columns from p.Bar. It doesn't realize that these columns are related and attempts to create them twice.

The reason why this doesn't seem correct to me is if I just change p.Foo's map so that it refers to p.Bar instead of p.Baz, SchemaExport does not generate duplicate columns. In this situation it appears to recognize that the columns in p.Foo's map and in the p.Bar class are related. My best theory at this point is that SchemaExport doesn't consider columns inherited via union-subclass when it is deciding whether it should add columns to a class in order to support a map. That seems like a bug to me.

I have to have fooId and name columns declared in p.Bar because we use our mapping files for schema and code generation. If I only declare the fooId and name columns within p.Foo's map, code generation won't work correctly.

So I'm still searching for a solution to this problem. Does anyone else have a suggestion? Is it time for a bug report?

Thanks,
Jeff


Top
 Profile  
 
 Post subject: Is it an abstract class
PostPosted: Thu Mar 01, 2007 11:52 pm 
Newbie

Joined: Mon Feb 19, 2007 12:54 am
Posts: 16
Location: banglore, india
The super is an abstract class? If it is abstract it will not include the fields form abstract class

_________________
Banglore Developer


Top
 Profile  
 
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.