Tuesday 13 April 2010

Ill-Advised Hibernate Mapping Quandary

I'm wondering if this is possible:

class Idea {
Collection primaryTags;
Collection secondaryTags;
}

class Proposal {
Collection
primaryTags;
Collection
secondaryTags;
}

Mapped to:

CREATE TABLE (
IDEA_ID VARCHAR(36), /* Foreign key */
PROPOSAL_ID VARCHAR(36), /* Alternate key */
TAG VARCHAR(100), /* Whatever was in the String */
TAG_TYPE VARCHAR(9) /* 'PRIMARY' or 'SECONDARY' */
);

I'm thinking.. no. My problem is that I can't see a way to get Hibernate to take care of the TAG_TYPE column - a value that exists in the database, and must be inserted whenever new rows are inserted, but has a value specific to the domain collection whence it came.

Hibernate supports computed properties, but those exist on the domain side, and not in the database. I want the opposite! :-)

No comments:

Post a Comment