java - Hibernate: How to Map Composite Keys? -


i have table 3 composite keys. custom_id, patient_idpatient, service_provider_type_idservice_provider_type. current mapping below

<?xml version="1.0" encoding="utf-8"?> <!doctype hibernate-mapping public "-//hibernate/hibernate mapping dtd 3.0//en" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping>     <class name="beans.serviceprovider" table="service_provider" catalog="myglukose" optimistic-lock="version">         <id name="customid" type="string">             <column name="custom_id" not-null="true"/>         </id>         <many-to-one name="patient" class="beans.patient" fetch="select">             <column name="patient_idpatient" not-null="true"/>         </many-to-one>         <many-to-one name="serviceprovidertype" class="beans.serviceprovidertype" fetch="select">             <column name="service_provider_type_idservice_provider_type" not-null="true"/>         </many-to-one>         <property name="datecreated" type="timestamp">             <column name="date_created" length="19" />         </property>         <property name="lastupdated" type="timestamp">             <column name="last_updated" length="19" not-null="true" />         </property>     </class> </hibernate-mapping> 

my sql code

create table if not exists `xxx`.`service_provider` (   `custom_id` varchar(45) not null,   `patient_idpatient` int not null,   `service_provider_type_idservice_provider_type` int not null,   `date_created` timestamp null,   `last_updated` timestamp not null default current_timestamp,   index `fk_service_provider_patient1_idx` (`patient_idpatient` asc),   index `fk_service_provider_service_provider_type1_idx` (`service_provider_type_idservice_provider_type` asc),   primary key (`custom_id`, `patient_idpatient`, `service_provider_type_idservice_provider_type`),   constraint `fk_service_provider_patient1`     foreign key (`patient_idpatient`)     references `xxx`.`patient` (`idpatient`)     on delete cascade     on update no action,   constraint `fk_service_provider_service_provider_type1`     foreign key (`service_provider_type_idservice_provider_type`)     references `xxx`.`service_provider_type` (`idservice_provider_type`)     on delete no action     on update no action) engine = innodb; 

how can map these 3 composite keys in hibernate?

i know maybe have

<composite-id name="compid">    <key-property name="customid” column="custom_id" />    <key-property name="patientidpatient" column="patient_idpatient" />    <key-property name="serviceprovidertypeidserviceprovidertype" column="service_provider_type_idservice_provider_type" /> </composite-id> 

but not sure how apply xml mapping, whether should "just" add code, whether should remove first or make edits first. tried removing primary key mapping , relationship key mappings , adding above code, didnt work, ended multiple errors @ different times.

what correct way of mapping this? making edit existing xml code appreciated have complete picture of how should make work.


Comments

Popular posts from this blog

4x4 Matrix in Python -

python - String indices must be integers and while issue -

python - PyInstaller UAC not working in onefile mode -