Honestly I don't fully understand why column name in key-many-to-one of IdentityAttribute table should be the same as id column name in User table.
I still went ahead and changed it the way you suggested.
Unfortunately it did not fix the problem.
I would really like to know what wrong this this mapping, but I have a deadline to meet :). So I decided to change DB schema and mapping (see below) it looks simpler to me and works fine.
I really appreciate all your time an help. Even I was not able to fix the problem I still was able to learn some things.
Thanks a lot, Alexi
Code:
<class name="Identity" table="Identity" >
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" column="name" />
<map name="attributeMap" cascade="all" lazy="true">
<key column="identityId" />
<map-key type="java.lang.String" column="name" />
<one-to-many class="IdentityAttribute" />
</map>
<many-to-one
name="parent"
column="parentId"
class="Identity"
/>
</class>
<class name="IdentityAttribute" table="IdentityAttributeName">
<id name="id" column="id">
<generator class="native"/>
</id>
<property name="name" column="name" />
<set name="values" table="IdentityAttributeValue">
<key column = "identityAttributeNameId" />
<element type="java.lang.String" column="value"/>
</set>
</class>
Code:
CREATE TABLE Identity (
id BIGINT generated by default as identity (start with 1),
parentId BIGINT,
name VARCHAR(50),
identityType VARCHAR (12),
email VARCHAR(50),
primary key (id)
);
CREATE TABLE IdentityAttributeName (
id BIGINT generated by default as identity (start with 1),
identityId BIGINT ,
serviceId VARCHAR(50),
name VARCHAR(50) NOT NULL,
primary key (id)
);
CREATE TABLE IdentityAttributeValue (
id BIGINT generated by default as identity (start with 1),
identityAttributeNameId BIGINT NOT NULL,
value VARCHAR(50) NOT NULL,
primary key (id)
);