How to create a map property that has both a key column and a map key as part of a PK part class?
Like this:
<class entity-name="Person" >
<id name="id"/>
<property name="birthDate" type="date"/>
<map name="names">
<key column="personId"/>
<map-key type="string" column="code"/>
<one-to-many class="PersonName" />
</map>
</class>
<class entity-name="PersonName">
<composite-id>
<key-many-to-one name="personId" class="Person"/>
<key-property name="code" type="string" length="32"/>
</composite-id>
<property name="lastName" type="string" length="64" index="nameSearch"/>
<property name="firstName" type="string" length="64" index="nameSearch"/>
<property name="middleName" type="string" length="64" index="nameSearch"/>
<property name="isActual" type="boolean"/>
</class>
I need to avoid creating a surrogate key in the PersonName class, which requires special handling. Json, shown below, should be automatically saved in the database, insert and update detailed records, when necessary, based on the PersonId code.
Naturally, the "code" property identifies the string along with the identifier of the person.
I tried different combinations of "reverse", "non-zero", etc. I admit that I do not fully understand how this works. I get various error messages, for example:
: null "" NOT NULL
: Erroreous row (null, null, lastname, ffffirst, null, null).
org.hibernate.MappingException: : PersonName: person ( insert = "false" update = "false" )
, json:
{
"birthDate": "33-44-55",
"names": {
"mainName": {
"lastName": "lastname",
"firstName": "ffffirst"
},
"maidenName": {
"lastName": "lastname1",
"firstName": "ffffirst2"
},
"old": {
"lastName": "lastname3",
"firstName": "ffffirst4"
}
}
}
UPD ( )
- , json. json . "id", , , , . ( "" ) "id". "personId" "code".
** 2 **
json, , . xml, . , json.
, !
, , :
CREATE TABLE personname
(
personid character varying(32) NOT NULL,
code character varying(32) NOT NULL,
lastname character varying(64),
firstname character varying(64),
middlename character varying(64),
isactual boolean,
CONSTRAINT personname_pkey PRIMARY KEY (personid, code),
CONSTRAINT fk_1skg5frawyftx8co9uawhc3r8 FOREIGN KEY (personid)
REFERENCES person (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)