-->
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 composite-key generation
PostPosted: Fri Apr 09, 2004 2:58 am 
Newbie

Joined: Fri Apr 09, 2004 2:21 am
Posts: 6
Hi all,
i use an Oracle 8 & 9 Database.
I generated the mappings with middlegen and the code with hbm2java.

There is a table 'Antrag' which has a composite foreign key (LBID, ZUSTSB) to table 'Mitarb' with primary key (LBID,MITARBID).

When I run a simple test with table 'mitarb' I get the following Exception:
Code:
java.lang.ExceptionInInitializerError
   at java.lang.Class.forName0(Native Method)
   at java.lang.Class.forName(Class.java:141)
   at com.intellij.rt.execution.application.AppMain.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception building SessionFactory: Foreign key (ANTRAG [LBID,ZUSTSB])) must have same number of columns as the referenced primary key (MITARB [MITARBID])

In the mapping for 'Mitarb' I found the composite primary key not correctly generated:
Code:
<composite-id name="comp_id" class="de.nrw.brd.osip.lvn.db.hibernate.MitarbPK">
        <key-property
            name="mitarbid"
            column="MITARBID"
            type="java.math.BigDecimal"
            length="22"
        />
</composite-id>   

I tried to generate the mapping without the referencing table 'ANTRAG ' and all was well:
Code:
<composite-id name="comp_id" class="de.nrw.brd.osip.lvn.db.hibernate.MitarbPK">
        <key-property
            name="mitarbid"
            column="MITARBID"
            type="java.math.BigDecimal"
            length="22"
        />
        <key-property
            name="lbid"
            column="LBID"
            type="java.math.BigDecimal"
            length="22"
        />
</composite-id>   

Hibernate 2.1.2
middlegen-2.0-vo.jar
middlegen-hibernate-plugin-2.0-vo.jar

Can somone give me kick what's running wrong?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 09, 2004 4:33 am 
Newbie

Joined: Fri Apr 09, 2004 2:21 am
Posts: 6
Annotation: The middlegen-gui shows the correct relations, but when I say 'generate' the Primary key of 'mitarb' is not correctly generated.

Image



Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="de.nrw.brd.osip.lvn.db.hibernate.Mitarb"
    table="MITARB"
>

    <composite-id name="comp_id" class="de.nrw.brd.osip.lvn.db.hibernate.MitarbPK">
        <key-property
            name="mitarbid"
            column="MITARBID"
            type="java.math.BigDecimal"
            length="22"
        />
    </composite-id>   

    <property
        name="vname"
        type="java.lang.String"
        column="VNAME"
        not-null="true"
        length="50"
    />
    <property
        name="nname"
        type="java.lang.String"
        column="NNAME"
        not-null="true"
        length="50"
    />
    <property
        name="mitarbkz"
        type="java.lang.String"
        column="MITARBKZ"
        length="10"
    />
    <property
        name="tel"
        type="java.lang.String"
        column="TEL"
        length="50"
    />
    <property
        name="fax"
        type="java.lang.String"
        column="FAX"
        length="50"
    />
    <property
        name="vertreter"
        type="java.lang.String"
        column="VERTRETER"
        length="50"
    />

    <!-- associations -->
    <!-- bi-directional one-to-many association to Antrag -->
    <set
        name="antrags"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="LBID" />
            <column name="ZUSTSB" />
        </key>
        <one-to-many
            class="de.nrw.brd.osip.lvn.db.hibernate.Antrag"
        />
    </set>
    <!-- bi-directional many-to-one association to Benutzer -->
    <many-to-one
        name="Benutzer"
        class="de.nrw.brd.osip.lvn.db.hibernate.Benutzer"
        not-null="true"
    >
        <column name="LBID" />
        <column name="BENID" />
    </many-to-one>

</class>
</hibernate-mapping>



Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 10, 2004 3:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
OK this is interesting. This should have worked fine. The CVS version has all know bugs fixed other than one (which is a pain hence why I have not finsihed it) I would be interested in you trying your schema using the CVS version. If it does not work I would like to know. Please create a JIRA entry to make sure and reference this thread so it reminds me to look at it.

BTW: The GUI snap shot is helpfull - Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 14, 2004 6:52 am 
Newbie

Joined: Fri Apr 09, 2004 2:21 am
Posts: 6
the behaviour with the cvs version seems to be the same as with version 2.0-vo. I'll create a new entry in jira.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 14, 2004 7:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
OK - I iwill check it out. Thanks for trying the CVS version out.


Top
 Profile  
 
 Post subject:
PostPosted: Sun May 23, 2004 1:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I just checked in the fix for this - try it out from the CVS version.
BTW: Keep in mind that the changes take time to be propated to the SF anon CVS servers.


Top
 Profile  
 
 Post subject: Fix works for me
PostPosted: Wed Jul 21, 2004 1:31 pm 
Beginner
Beginner

Joined: Mon Jun 21, 2004 2:41 pm
Posts: 40
Just wanted to let you know that the R5 fixed the issue.

Funny thing is that I didn't even notice this until I downloaded R5 today and was trying to decide weither to have the PK in the class or in a seperate generated class.

-David


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.