-->
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.  [ 25 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: middlegen and composit keys
PostPosted: Thu Oct 02, 2003 4:48 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:35 pm
Posts: 35
All, It appears as though the the middlegen plugin is not properly generating the composite key entries within the *.hbm.xml.

In my system, I have multiple tables with two keys. The middlegen GUI properly identifies it as needing a compound key and a primary key class, but the entires do not generated into the *.hbm.xml files. This leads to SAXParsing exceptions when I run the hbm2java tool.

The version of the jar files I am using are as follows:

xdoclet-1.2b4.jar
xdoclet-hibernate-module-1.2b4.jar
xdoclet-xdoclet-module-1.2b4.jar


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2003 6:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
R2 Middlegen should generate correct hbms for compound keys. R1 did not work correctly for Many-to-Many with compound keys which was fixed in R2. I may have missed one situation so I am keen that you detail the relationship and the output generated as you have not provided enough information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2003 4:35 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
Hi I have the same problem.

I have one table with one key compounded of two foreign keys and one date and here is the result :

Code:
<class name="TchgtService" table="TCHGT_SERVICE">
  <composite-id name="comp_id" class="TchgtServicePK">
    <key-property name="numService" column="NUM_SERVICE" type="java.lang.Integer"/>
    <key-property name="cleSalarie" column="CLE_SALARIE" type="java.lang.Integer"/>
    <key-property name="dateChgtServ" column="DATE_CHGT_SERV" type="java.util.Date"/>
  </composite-id>   
  <many-to-one name="tservice" class="Tservice" not-null="true">
    <column name="NUM_SERVICE" />
  </many-to-one>   
  <many-to-one name="tsalarie" class="Tsalarie" not-null="true">
    <column name="CLE_SALARIE" />
  </many-to-one>   
</class>


Here the generation is ok but I have one question : why is the composite-id made of 'key-property' and why not use 'key-many-ot-one'. Is it a limitation of the tool or an hibernate 'best-practice' ?

Secondly, I have another class where the primary key is compounded just of two foreign keys. With this class, middlegen does not generate the compound key.

Code:
<class name="AbsenceJour" table="TABSENCE_JOUR">
  <property name="valeurCptJour" type="java.lang.Integer" column="VALEUR_CPT_JOUR" length "10"/>
  <property name="valeurCptHeure" type="java.lang.Integer" column="VALEUR_CPT_HEURE" length="10"/>
  <property name="nbFiche" type="java.lang.Short" column="NB_FICHE" length="5"/>
  <many-to-one name="cumulJour" class="CumulJour" not-null="true">
    <column name="NUM_CUMUL" />
  </many-to-one>   
  <many-to-one name="motifAb" class="MotifAb" not-null="true">
    <column name="NUM_MOTIF" />
  </many-to-one>   
</class>


(In the database the primary key is compounded of 'NUM_CUMUL' and 'NUM_MOTIF')

Seb
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2003 4:46 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
One more thing : is it possible to find somewhere the source code of the r2 version ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2003 6:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Hmmmm..... It does not deal with a mix of foreign keys on elements of the compound keys. I will have to deal with that issue. The source can be found in either the Middlegen CVS or the JIRA entry for the plugin. Use the Middlegen doco on this site for the links.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2003 8:04 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
I made some little modifications on the vm file and now it deals with composite-id just made of foreign-keys. Do you want me to post what I did ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 03, 2003 11:27 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Great. Please email it to david@hibernate.org and/or to the Middlegen JIRA under the plugin category.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 10:28 am 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:35 pm
Posts: 35
All,

My situation is the same, if you have a compound key that is made up of foreign keys, then it does not get properly generated. Any word on when I can get the new templates? Is that all that is required for this change?

Thanks in advance!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 06, 2003 10:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
All the information is there its just setting up the appropriate mapping tags for it to work correctly. Obviously it complicates the template somewhat, I have been waiting for the submission from scesbron. If I don't get it very soon I will do it myself.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 1:41 pm 
Beginner
Beginner

Joined: Thu Sep 25, 2003 5:22 pm
Posts: 29
Location: NC
Any update on this? I just found the same exact problem as the second scenario that scesbron described with two foreign keys making up the primary key. I would love to be emailed that solution, at kathryn@cs.duke.edu.

Thanks!
Kat


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2003 7:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I have not received anything as yet so I will do it today when a spot of time opens up.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2003 4:31 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:35 pm
Posts: 35
David,

Thanks! Hey, I am not sure if this is related, but when I went to deply, I got the following error:

15:06:06,280 INFO [HibernateServiceMBean] Could not build SessionFactory using the MBean classpath - will try again using client classpath: Repeated column in mapping for class com.ronmar.homepage.hibernate.ContactInfo should be mapped with insert="false" update="false": navigation_sub_id

If you can take care of this as well. I am looking at the work around for the time being, but I have yet to find one.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2003 5:28 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:35 pm
Posts: 35
It appears as though the many-to-one associates need the in order to keep Hibernate happy.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2003 5:33 pm 
Beginner
Beginner

Joined: Thu Sep 25, 2003 5:22 pm
Posts: 29
Location: NC
I think that the error we are referring to here is because of using middlegen to generate our *.hbm.xml files from a pre-existing database. Somehow it doesn't seem to read a compounded primary key that consists of two foreign keys and create the proper mapping file. I believe that this is a bug with middlegen? But anyhow, I think that your problem was with a hand-coded *.hbm.xml file and is probably not related.

However, I would really like to see this fix as soon as it is convenient...

-Kat


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 10, 2003 4:11 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
First I want to apologize.

There's some problems on my company mail server and as I do not receive mail from Hibernate forum manager I thought no reply was made to my post.

I just find that my workaround is not good. It deals with the case where there is only foreign keys in the composite-id but it does not use <key-many-to-one> but <key-property> and <many-to-one>. Thus I also have the duplicate declaration and the error message that tells me to put insert=false and update=false on the property.

David, do you want me to post something (even if I am a bit late) or not ?

Apologize

Seb


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 25 posts ]  Go to page 1, 2  Next

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.