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: Exception with nested column tag in many-to-one mapping
PostPosted: Mon Mar 10, 2008 10:44 am 
Newbie

Joined: Sun Jul 29, 2007 9:10 am
Posts: 8
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

3.1.3

Hello

Is there a difference between the column attribute and the nested column tag of a many-to-one mapping? Until now I didn't think so. But I ran into the following problem.

I changed this section of my mapping file:

Code:
<joined-subclass name="de.iteratec.iteraplan.model.BusinessprocessCoverage" table="bproccov" lazy="false">
      <key column="id" />
      <many-to-one name="businessprocess" not-null="true" cascade="none" fetch="select" lazy="proxy">
        <column name="bproc_idBproc" />
      </many-to-one>
      <many-to-one name="ipurelease" not-null="true" cascade="none" fetch="select" lazy="proxy">
        <column name="ipurel_idRel" />
      </many-to-one>
      <many-to-one name="organizationalunit" not-null="true" cascade="none" fetch="select" lazy="proxy">
        <column name="orgunit_idOrgunit" />
      </many-to-one>
      <many-to-one name="product" not-null="true" cascade="none" fetch="select" lazy="proxy">
        <column name="product_id" />
      </many-to-one>
</joined-subclass>


to this version:

Code:
<joined-subclass name="de.iteratec.iteraplan.model.BusinessprocessCoverage" table="bproccov" lazy="false">
      <key column="id" />
      <many-to-one name="businessprocess" column="bproc_idBproc" not-null="true" cascade="none" fetch="select" lazy="proxy" />
      <many-to-one name="ipurelease" column="ipurel_idRel" not-null="true" cascade="none" fetch="select" lazy="proxy" />
      <many-to-one name="organizationalunit" column="orgunit_idOrgunit" not-null="true" cascade="none" fetch="select" lazy="proxy" />
      <many-to-one name="product" column="product_id" not-null="true" cascade="none" fetch="select" lazy="proxy" />
</joined-subclass>


The only thing I did was basically remove the nested column tags and replace them with a column attribute in the many-to-one mapping. Apart from that I didn't change anything else. No line of code. No other parts of the mapping.

With the new version (the second mapping) I get a PropertyValueException when trying to save an object of the mapped subclass.

Can anybody tell me if there's a difference between these two versions that would result in such an exception?

Thanks
Martin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 18, 2008 1:13 pm 
Newbie

Joined: Sun Jul 29, 2007 9:10 am
Posts: 8
If anybody's interested, I think I finally found the reason for the exception. I compared the generated DDL in MySQL with both of the above versions of the mapping file. It seems that the not-null constraint is not generated if the column tag is nested. On the other hand it IS generated if the column attribute is used. So the exception I got was probably due to some implementation error of mine because I obviously inserted null values into columns that shouldn't be null. But the database didn't enforce the constraint so I never realized my error.

DDL with mapping containing nested column tag:
Code:
CREATE TABLE `bproccov` (                                                                               
  `id` int(11) NOT NULL default '0',                                                                     
  `bproc_idBproc` int(11) default NULL,                                                                 
  'ipurel_idRel` int(11) default NULL,                                                                   
  `orgunit_idOrgunit` int(11) default NULL,                                                             
  `product_id` int(11) default NULL,
   ...);


DDL with mapping containing column as attribute:
Code:
CREATE TABLE `bproccov` (                                                                               
  `id` int(11) NOT NULL default '0',                                                                     
  `bproc_idBproc` int(11) NOT NULL default '0',                                                     
  'ipurel_idRel` int(11) NOT NULL default '0',                                                                 
  `orgunit_idOrgunit` int(11) NOT NULL default '0',                                                   
  `product_id` int(11) NOT NULL default '0', 
   ...);


Even though I know that some people don't like it if you just scream out 'that's a bug in Hibernate', I'll go as far out on the limb ;): I think that's a bug in Hibernate and I will search through the bug database if something similar has already been reported...

Cheers
Martin


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.