-->
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.  [ 2 posts ] 
Author Message
 Post subject: Key-many-to-one problem !
PostPosted: Wed Sep 01, 2010 3:39 pm 
Newbie

Joined: Tue Aug 31, 2010 4:14 pm
Posts: 1
This is a huge drawback... the element
Code:
<key-many-to-one/>
inside the
Code:
<composite-id/>
element doesn't have a "type" definition attribute like
Code:
<key-property/>
has.

The problem is, when you don't specify the type definition (like integer, or string HB native types) of a specific key, Hibernate tries to map the database/PO definition to its internal definition, example, if MySQL uses a type of "INT", then HB tries to map this type to "int" and not to "integer", the correct mapping type, resulting to a set of terrible erros like the ones described bellow:
Code:
Caused by: org.hibernate.MappingException: An association from the table XXX_ENTITY_XXX refers to an unmapped class: int
   at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1343)
   at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1261)
   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1377)
   at com.unoware.services.ubw.HibernateSessionFactoryWrapper.<init>(HibernateSessionFactoryWrapper.java:57)
   at com.unoware.services.ubw.HibernateSessionFactoryWrapper.<clinit>(HibernateSessionFactoryWrapper.java:51)
   at java.lang.J9VMInternals.initializeImpl(Native Method)
   at java.lang.J9VMInternals.initialize(J9VMInternals.java:200)
   ... 4 more


This problem only occurs when using
Code:
<key-many-to-one/>
because the "type" attribute isn't defined on the HB DTD. A solution for that problem is to only use the
Code:
<key-property/>
element inside a composed ID definition. The problem with this approach is that all the keys from the parent entity must be also necessary defined on both association directions, "one-to-many" and "many-to-one" (if both sides have an association). This situation (parent keys == child foreign keys) are almost unlike to occur on real world scenarios.
Code:
Example 1 (Okay):
Parent                       Child
=========                    ========
id1 (PK)           =>        id1(FK)
id2 (PK)           =>        id2(FK)

Example 2 (Problem):
Parent                       Child
==========                  ========
id1 (PK)           =>        id1(FK)
id2 (PK)


I solved my problem replacing all the
Code:
<key-many-to-one/>
to
Code:
<key-property/>
elements (that have the native "type" attribute). This is a huge drawback, and I really hope that in future releases this problem is corrected.

Hibernate Version: 3.x


Top
 Profile  
 
 Post subject: Re: Key-many-to-one problem !
PostPosted: Thu Sep 02, 2010 7:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
This is the wrong forum for this type of posts. You should use the Hibernate Users one.


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