-->
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.  [ 7 posts ] 
Author Message
 Post subject: middlegen order composite keys
PostPosted: Thu Dec 09, 2004 12:24 pm 
Newbie

Joined: Tue Nov 02, 2004 12:48 pm
Posts: 7
Location: Bamberg / Germany
Hibernate version: 2.1.6

Name and version of the database you are using:SAPDB 7.3

I generate with middlegen my hbm.xml files.

In the composite key looks like that:

<composite-id name="comp_id" class="de.ihb.aaa.ko.std.yyyyPK">
<key-property
name="matrnr"
column="MATRNR"
type="java.lang.Integer"
length="10"
/>
<key-property
name="studfach"
column="STUDFACH"
type="java.lang.String"
length="5"
/>
<key-property
name="studab"
column="STUDAB"
type="java.lang.Integer"
length="10"
/>^M
<key-property
name="studabver"
column="STUDABVER"
type="java.lang.Integer"
length="10"
/>^M
<key-property
name="studentfach"
column="STUDENTFACH"
type="java.lang.String"
length="5"^M
/>
</composite-id>

The order is: matrnr, studfach, studab etc..
The order seems to be the order of the order the columns are created.

The Set Tag in the hbm.xml-file of yyy looks like this:


<set
name="xxx"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="STUDENTFACH" />
<column name="MATRNR" />
<column name="STUDFACH" />
<column name="STUDAB" />
<column name="STUDABVER" />
</key>
<one-to-many
class="de.ihb.aaa.ko.std.xxx"
/>
</set>

Here seems to be the order like the foreign key or the primary key.
Is there any way to tell middlegen how to make the order?
Or why is the sort order different.

I got the following error:

Data types must be compatible, when I try to fetch the set with
getXxx () and make the Iteration.

Has anyone help for me.

Regards


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 09, 2004 10:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I have never found a case where the order was incorrectly gathered (since it gets if from the database) unless you have partial foreign key relationships on the table and you don't generate plain compound keys. Not sure whats going on maybe a small screen shot of the relationship shown in Middlegen.


Top
 Profile  
 
 Post subject: middlegen order composite keys
PostPosted: Fri Dec 10, 2004 6:27 am 
Newbie

Joined: Tue Nov 02, 2004 12:48 pm
Posts: 7
Location: Bamberg / Germany
Thank you for your quick answer.

Here my input into the build.xml

<middlegen
appname="Toolset"
prefsdir="${basedir}"
gui="true"
databaseurl="${db.url}"
driver="com.sap.dbtech.jdbc.DriverSapDB"
username="yyy"
password="xxx"
schema="yyy"
>
<table name="STUDENTVER" singular="Studentver" plural="Studentvers"/>
<table name="STUDIUM" singular="Studium" plural="Studiums"/>
<table name="PRFSTD" singular="Prfstd" plural="prfstd"/>
<hibernate
destination="${gensrc.dir}"
package="de.ihb.aaa.ko"
javaTypeMapper="de.ihb.middlegen.TypeMapper"
plainCompoundKeys="true"
genLazyNotProxy="true"
proxy="true"
/>

</middlegen>

----------------------------------------------------------

And here the result of the output of middlegen-build

----------------------------------------------------------
Studentver.hbm.xml

<composite-id name="comp_id" class="de.ihb.aaa.ko.StudentverPK">
<key-property
name="matrnr"
column="MATRNR"
type="java.lang.Integer"
length="10"
/>
<key-property
name="studfach"
column="STUDFACH"
type="java.lang.String"
length="5"
/>
<key-property
name="studab"
column="STUDAB"
type="java.lang.Integer"
length="10"
/>
<key-property
name="studabver"
column="STUDABVER"
type="java.lang.Integer"
length="10"
/>
<key-property
name="studentfach"
column="STUDENTFACH"
type="java.lang.String"
length="5"
/>
</composite-id>

<!-- bi-directional one-to-many association to Studium -->
<set
name="Studiums"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="STUDENTFACH" />
<column name="MATRNR" />
<column name="STUDFACH" />
<column name="STUDAB" />
<column name="STUDABVER" />
</key>
<one-to-many
class="de.ihb.aaa.ko.Studium"
/>
</set>

-------------------------------------------------------------------
Studium.hbm.xml
<composite-id name="comp_id" class="de.ihb.aaa.ko.StudiumPK">
<key-property
name="matrnr"
column="MATRNR"
type="java.lang.Integer"
length="10"
/>
<key-property
name="studfach"
column="STUDFACH"
type="java.lang.String"
length="5"
/>
<key-property
name="studab"
column="STUDAB"
type="java.lang.Integer"
length="10"
/>
<key-property
name="studabver"
column="STUDABVER"
type="java.lang.Integer"
length="10"
/>
<key-property
name="fachgruppe"
column="FACHGRUPPE"
type="java.lang.Integer"
length="10"
/>
<key-property
name="prffach"
column="PRFFACH"
type="java.lang.Integer"
length="10"
/>
<key-property
name="prffachver"
column="PRFFACHVER"
type="java.lang.Integer"
length="10"
/>
<key-property
name="studentfach"
column="STUDENTFACH"
type="java.lang.String"
length="5"
/>
</composite-id>

---------------------------------------------------------------------------------

I hope this would help, for the solution.

I found the tag sortColumns , what does this do.
Only sort the columns to the hbm-file properties or
also foreign keys for the set.

Regards
Gerlinde


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 10, 2004 11:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Hmmmm. Does it do the same when you do not include the table tags?
Middlegen uses the JDBC driver to collect the data fields. The hibernate plugin (under recommended usage situations) does not re-order the key fields. I'll give it a go on this end when I have a chance but my local test database (using HSQLDB) does not exhibit this behaviour. Then again I tend not to use the table tags. Thanks for the info.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 7:25 am 
Newbie

Joined: Tue Nov 02, 2004 12:48 pm
Posts: 7
Location: Bamberg / Germany
Thanks for the answer,
the behavior ist the same
with or without table-tag.
I only take the tag, that I do not need to post all files.

I know that middlegen is making the problem.
Which order take middlegen for
to make an input like this:
<set
name="studentvers"
lazy="true"
inverse="true"
cascade="none"
>
<key>
<column name="STUDENTFACH" />
<column name="MATRNR" />
</key>
<one-to-many
class="de.ihb.aaa.ko.std.Studentver"
/>
</set>

order of the columns in the former create statement
order of the primary key
order of the foreign key?

Regards Gerlinde


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 6:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Middlegen builds an internal data model of the database which is used to create the code.

What version of Middlegen are you using?

Can you provide a simple (two table is best) DDL script that exhibits this problem. I will take a look at it.
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 1:36 pm 
Newbie

Joined: Tue Nov 02, 2004 12:48 pm
Posts: 7
Location: Bamberg / Germany
Below the DDLs, with two tables there is no problem.
I sent you the relevant DDLs.

Thank you for your help.

Regards

create table FAK (BEZ VARCHAR(70) NOT NULL , FAK INTEGER NOT NULL , ZEUGNISBEZ VARCHAR(100) , KURZBEZ VARCHAR(5) , PERSON INTEGER NOT NULL );
create table STUDIENGANG (BEZ VARCHAR(50) , STUDIENGANG INTEGER NOT NULL , APNR VARCHAR(20) , MAGISTER INTEGER );
create table STUDAB (STUDFACH VARCHAR(5) NOT NULL , STUDAB INTEGER NOT NULL , REIHENFOLGE VARCHAR(10) );
create table STUDABVER (STUDFACH VARCHAR(5) NOT NULL , STUDAB INTEGER NOT NULL , STUDABVER INTEGER NOT NULL , BEZ VARCHAR(100) NOT NULL);
create table STUDENT (MATRNR INTEGER NOT NULL , VORNAME VARCHAR(50) , NACHNAME VARCHAR(50) , SEX INTEGER NOT NULL , NUTZER VARCHAR(50) , ORT1 VARCHAR(50) );
create table STUDENTFACH (MATRNR INTEGER NOT NULL , STUDFACH VARCHAR(5) NOT NULL , FACHSEM INTEGER NOT NULL , STATUS INTEGER NOT NULL , IMMASEM INTEGER , EXMASEM INTEGER , IMMAFACHSEM INTEGER , ABSCHLUSS INTEGER , POAKTUELL INTEGER NOT NULL , IMMADATUM DATE , EXMADATUM DATE , HAUPTFACH INTEGER , FACHSEMDELTA INTEGER , UNIV INTEGER NOT NULL , ABSCHLUSSAUFBAU INTEGER , NFS INTEGER , APNR VARCHAR(20) , APABSCHLUSS VARCHAR(20) , APSTGNR VARCHAR(2) , SATZUNG INTEGER DEFAULT -1);
create table STUDENTVER (MATRNR INTEGER NOT NULL , STUDFACH VARCHAR(5) NOT NULL , STUDAB INTEGER NOT NULL , STUDABVER INTEGER NOT NULL , STUDENTFACH VARCHAR(5) NOT NULL , NOTE_ FIXED(5,2) , ID_TA INTEGER , SEMESTER_BEGINN INTEGER , NOTEUSER VARCHAR(50) , NOTEZEIT TIME , NOTEDATUM DATE , NUTZER VARCHAR(50) , ZEITSTEMPEL TIMESTAMP , PO INTEGER NOT NULL , SEMESTER_ENDE INTEGER , LOGIN_ VARCHAR(50) , KREDITFREI_ALT INTEGER , VLG INTEGER , KREDIT FIXED(8,2) , KREDITFREIWILLIG FIXED(8,2) , ZUSATZSEMESTER INTEGER , ANERKSEMESTER INTEGER );

alter table STUDFACH ADD PRIMARY KEY ( STUDFACH ) ;
alter table FAK ADD PRIMARY KEY ( FAK ) ;
alter table STUDIENGANG ADD PRIMARY KEY ( STUDIENGANG ) ;
alter table STUDABVER ADD PRIMARY KEY ( STUDFACH, STUDAB, STUDABVER ) ;
alter table STUDABVER ADD PRIMARY KEY ( STUDFACH, STUDAB, STUDABVER ) ;
alter table STUDENT ADD PRIMARY KEY ( MATRNR ) ;
alter table STUDENTFACH ADD PRIMARY KEY ( MATRNR, STUDFACH ) ;
alter table STUDENTVER ADD PRIMARY KEY ( STUDENTFACH, MATRNR, STUDFACH, STUDAB, STUDABVER ) ;

alter table STUDFACH add foreign key (FAK) references FAK(FAK ) ;
alter table STUDFACH add foreign key (STUDIENGANG) references STUDIENGANG(STUDIENGANG ) ;
alter table STUDAB add foreign key (STUDFACH) references STUDFACH(STUDFACH ) ;
alter table STUDABVER add foreign key (STUDFACH, STUDAB) references STUDAB(STUDFACH, STUDAB ) ;
alter table STUDENTFACH add foreign key (STUDFACH) references STUDFACH(STUDFACH ) ;
alter table STUDENTFACH add foreign key (MATRNR) references STUDENT(MATRNR ) ;
alter table STUDENTVER add foreign key (MATRNR, STUDENTFACH) references STUDENTFACH(MATRNR, STUDFACH ) ;
alter table STUDENTVER add foreign key (STUDFACH, STUDAB, STUDABVER) references STUDABVER (STUDFACH, STUDAB, STUDABVER ) ;


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