I have been working on it for quite a while, but still can’t figure out what’s wrong with my code.
Each Service has multiple profiles, but each profile only has one Service.
Service
{
Long service_id; // primary key
... getter/setter
}
Profile
{
Long profile_id; // primary key
Long service_id; // foreign key
... getter and setter
}
in Profile.hbm.xml. I add
< many-to-one name="service_id" class="com.mot.diva.dto.Service" column="SERVICE_ID" cascade="save-update">
< /many-to-one>
Is it the correct way to map it?
Then design your object model accordingly. When using an ORM tool, you need to think object (entities) and relations between entities, not ids. The ORM will take care of PK, FK, joins, etc. So your code should be something like this:
And the
Profile.hbm.xmlmapping file:And in
Service.hbm.xml(because your association seems to be bi-directional):