-->
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.  [ 3 posts ] 
Author Message
 Post subject: Non-lazy bi-dir collection in only loads one row
PostPosted: Tue Oct 18, 2005 11:43 am 
Newbie

Joined: Tue Oct 18, 2005 11:35 am
Posts: 2
I'm seeing an odd problem with a bi-directional one-to-many collection below. I've verified that the database has a number of AttributeKey rows correctly associated with an AttributeTemplate, but when I look at the attributeKeyMap after it's loaded, only the first AttributeKey in the table is loaded.

Any ideas?

Hibernate version:
3.0.5

Mapping documents:

Code:
<hibernate-mapping package="com.whatever.myapp.entities">
   <class name="AttributeTemplate" table="attribute_template">
      <cache usage="read-write"/>
      <id name="id" type="integer" column="ID">
         <generator class="native"/>
      </id>
      <timestamp name="modDate" column="mod_date"/>
      <property name="createDate" column="create_date" type="timestamp" not-null="true" length="19"/>
      <many-to-one name="globalName" column="global_name" class="GlobalName" not-null="true"/>
      <map inverse="true" lazy="false" name="attributeKeyMap">
         <key column="ID" not-null="true"/>
         <map-key column="keyword" type="string"/>
         <one-to-many class="AttributeKey"/>
      </map>
      <set inverse="true" lazy="false" name="attributeSets">
         <key column="ID"/>
         <one-to-many class="AttributeSet"/>
      </set>
   </class>
</hibernate-mapping>

<hibernate-mapping package="com.whatever.myapp.entities">
   <class name="AttributeKey" table="attribute_key">
      <id name="id" type="integer" column="ID">
         <generator class="native"/>
      </id>
      <timestamp name="modDate" column="mod_date"/>
      <property name="createDate" column="create_date" type="timestamp" not-null="true" length="19"/>
      <property name="keyword" column="keyword" type="string" not-null="true" length="255"/>
      <property name="minValues" column="min_values" type="integer" not-null="false" length="11"/>
      <property name="maxValues" column="max_values" type="integer" not-null="false" length="11"/>
      <many-to-one name="type" column="type" class="AttributeType" not-null="true"/>
      <property name="defaultValue" column="default_value" type="string" not-null="false" length="255"/>
      <many-to-one name="attributeTemplate" column="attribute_template" class="AttributeTemplate"
         not-null="true"/>
      <set inverse="true" lazy="true" name="attributes">
         <key column="ID"/>
         <one-to-many class="Attribute"/>
      </set>
   </class>
</hibernate-mapping>

CREATE TABLE attribute_template (
  ID integer unsigned not null auto_increment,
  mod_date datetime not null default '2005-08-26',
  create_date datetime not null default '2005-08-26',
  global_name integer unsigned not null UNIQUE references global_name,
  PRIMARY KEY (ID),
  KEY FK_attribute_template_to_global_name (global_name),
   CONSTRAINT FK_attribute_template_to_global_name
   FOREIGN KEY (global_name) REFERENCES global_name (ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE attribute_key (
  ID integer unsigned not null auto_increment,
  mod_date datetime not null default '2005-08-26',
  create_date datetime not null default '2005-08-26',
  keyword varchar(255) not null,
  type integer unsigned not null references attribute_type,
  attribute_template integer unsigned not null references attribute_template,
  min_values integer,
  max_values integer,
  default_value varchar(255),
  PRIMARY KEY (ID),
  KEY FK_attribute_key_to_attribute_type (type),
   CONSTRAINT FK_attribute_key_to_attribute_type
   FOREIGN KEY (type) REFERENCES attribute_type (ID),
  KEY FK_attribute_key_to_attribute_template (attribute_template),
   CONSTRAINT FK_attribute_key_to_attribute_template
   FOREIGN KEY (attribute_template) REFERENCES attribute_template (ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;






Name and version of the database you are using:
MySql 4.1.13


Top
 Profile  
 
 Post subject: I use to define an association table
PostPosted: Tue Oct 18, 2005 12:29 pm 
Newbie

Joined: Wed Sep 17, 2003 3:31 am
Posts: 10
Location: Napoli (IT)
What you want is 'keword' to be the 'key' of the map (<map-key>), not of the association (<key>).
So you need another column or the association will be a set (that is, without an index).


<map inverse="true" lazy="false" name="attributeKeyMap">
<key column="template_id" not-null="true"/>
<map-key column="keyword" type="string"/>
<one-to-many class="AttributeKey"/>
</map>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 12:46 pm 
Newbie

Joined: Tue Oct 18, 2005 11:35 am
Posts: 2
Thanks for the response stefano. I didn't quite understand what you were saying with respect to the keyword, but when I looked at your example I realized that I completely misunderstood what the <key> element was supposed to do. So, I changed the column from "ID" to "attribute_template" and it works fine. I thought it was specifying the key column for the parent, and that Hibernate was automatically figuring out where the foreign-key column was on the child end.

Thanks for the help!

-d


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