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