-->
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.  [ 5 posts ] 
Author Message
 Post subject: Incorrect composite key generated for many-to-many mapping
PostPosted: Sat Sep 18, 2004 9:41 am 
Newbie

Joined: Sat Sep 18, 2004 8:58 am
Posts: 4
Hibernate version:
HIbernate 2.1.4
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="vobjects">
<class name="VObjectAlltypes" table="sspa_alltypes">
<id name="id" column="alltypes_id" type="string">
<generator class="uuid.hex"/>
</id>

<property name="lastModified" column="last_modified"/>
<property name="modifierId" column="modifier_id"/>
<property name="otherId" column="other_id"/>
<property name="dtShort" column="dt_short"/>
<property name="dtLong" column="dt_long"/>
<property name="dtInteger" column="dt_integer"/>
<property name="dtString" column="dt_string"/>
<property name="dtBoolean" column="dt_boolean"/>
<property name="dtString1" column="dt_string1"/>
<property name="dtString2" column="dt_string2"/>
<property name="dtString3" column="dt_string3"/>
<property name="dtString4" column="dt_string4"/>
<property name="dtString5" column="dt_string5"/>
<property name="dtString6" column="dt_string6"/>
<list name="SometypesList" table="sspa_all_some" lazy="true" inverse="false">
<key column="sometypes_id"/>
<index column="colIdx"/>
<many-to-many column="alltypes_id" class="vobjects.VObjectSometypes"/>
</list>
</class>
</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="vobjects">
<class name="VObjectSometypes" table="sspa_sometypes">
<id name="id" column="sometypes_id" type="string">
<generator class="uuid.hex"/>
</id>

<property name="lastModified" column="last_modified"/>
<property name="modifierId" column="modifier_id"/>
<property name="dtShort" column="dt_short"/>
<property name="dtLong" column="dt_long"/>
<property name="dtInteger" column="dt_integer"/>
<property name="dtString" column="dt_string"/>
<property name="dtBoolean" column="dt_boolean"/>
<property name="dtStringClob" column="dt_string_clob"/>
<list name="AlltypesList" table="sspa_all_some" lazy="true" inverse="true">
<key column="alltypes_id"/>
<index column="colIdx"/>
<many-to-many column="sometypes_id" class="vobjects.VObjectAlltypes"/>
</list>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:
Adaptive Server Anywhere Network Server Version 9.0.1.1751


The generated SQL (show_sql=true):
Buildfile: c:\nvdt\build.xml
run_schemaexport_tool:
[echo] ===== Running the schemaexport to update schema in database =====
[schemaexport] Sep 18, 2004 9:21:26 AM net.sf.hibernate.cfg.Environment <clinit>
[schemaexport] INFO: Hibernate 2.1.4
[schemaexport] Sep 18, 2004 9:21:26 AM net.sf.hibernate.cfg.Environment <clinit>

[schemaexport] drop table sspa_alltypes;
[schemaexport] drop table sspa_sometypes;
[schemaexport] drop table sspa_all_some;
[schemaexport] create table sspa_alltypes (
[schemaexport] alltypes_id VARCHAR(255) not null,
[schemaexport] last_modified DATETIME null,
[schemaexport] modifier_id VARCHAR(255) null,
[schemaexport] other_id VARCHAR(255) null,
[schemaexport] dt_short SMALLINT null,
[schemaexport] dt_long NUMERIC(19,0) null,
[schemaexport] dt_integer INT null,
[schemaexport] dt_string VARCHAR(255) null,
[schemaexport] dt_boolean TINYINT null,
[schemaexport] dt_string1 VARCHAR(255) null,
[schemaexport] dt_string2 VARCHAR(255) null,
[schemaexport] dt_string3 VARCHAR(255) null,
[schemaexport] dt_string4 VARCHAR(255) null,
[schemaexport] dt_string5 VARCHAR(255) null,
[schemaexport] dt_string6 VARCHAR(255) null,
[schemaexport] primary key (alltypes_id)
[schemaexport] );

[schemaexport] create table sspa_sometypes (
[schemaexport] sometypes_id VARCHAR(255) not null,
[schemaexport] last_modified DATETIME null,
[schemaexport] modifier_id VARCHAR(255) null,
[schemaexport] dt_short SMALLINT null,
[schemaexport] dt_long NUMERIC(19,0) null,
[schemaexport] dt_integer INT null,
[schemaexport] dt_string VARCHAR(255) null,
[schemaexport] dt_boolean TINYINT null,
[schemaexport] dt_string_clob VARCHAR(255) null,
[schemaexport] primary key (sometypes_id)
[schemaexport] );

[schemaexport] create table sspa_all_some (
[schemaexport] sometypes_id VARCHAR(255) not null,
[schemaexport] alltypes_id VARCHAR(255) not null,
[schemaexport] colIdx INT not null,
[schemaexport] primary key (alltypes_id, colIdx)
[schemaexport] );

[schemaexport] alter table sspa_all_some add constraint FKBE1F8900DE406342 foreign key (alltypes_id) references sspa_sometypes;
[schemaexport] alter table sspa_all_some add constraint FKBE1F89005DF9DB95 foreign key (sometypes_id) references sspa_alltypes;


Results from query to database showing that only alltypes_id and colIdx are composist pri ary keys.
table_id,column_id,pkey,domain_id,nulls,width,scale,unused,max_identity,column_name,remarks,default,unused2,user_type,format_str,column_type,remote_name,remote_type
441,1,'N',9,'N',255,0,0,0,'sometypes_id',,,,,,'R',,
441,2,'Y',9,'N',255,0,0,0,'alltypes_id',,,,,,'R',,
441,3,'Y',2,'N',4,0,0,0,'colIdx',,,,,,'R',,
Debug level Hibernate log excerpt:

_________________
Mousa


Top
 Profile  
 
 Post subject: Re: Incorrect composite key generated for many-to-many mappi
PostPosted: Sat Sep 18, 2004 9:48 am 
Newbie

Joined: Sat Sep 18, 2004 8:58 am
Posts: 4
Sorry I am new to this forum and forgot to explain my problem in initial posting.

I expected that the primary keys for the link table to be made of the primary key of both mapping tables. So for the sspa_all_some table the primary keys would be composed of alltypes_id and sometypes_id. What am I doing wrong?

_________________
Mousa


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 18, 2004 9:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use a <set> instead of a <list>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 18, 2004 2:01 pm 
Newbie

Joined: Sat Sep 18, 2004 8:58 am
Posts: 4
Thanks the set did create the correct composite key.

However, I need to use list because the order is needed, any other workarounds? Is this going to be fixed in the 3.0 version, or is it my misunderstanding of the list functionality?

_________________
Mousa


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 18, 2004 8:15 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
There is nothing to be fixed. This is correct.


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