Mapping an additional column to a composite-id while keeping the property-mapping for it
im using an intermediate entity-class to map additional columns to a jointable and it works fine as long as the Id will be generated from the both fkeys from the involved tables.
I want to implement a 3rd column "revision" from the same entity-class into the composite-id, and still need to use it with normal property-mapping. The composite-id mapping works fine, but the normal mapping for "revision" isnt.
I havnt found a good solution without using redundant data/columns for this problem, but i wonder why ,using entity-classes for jointables with extracolumns is a common way?
I would be gratefull for informations about how to map this correctly, or for informative links about it, thank you for help.
" Initial SessionFactory creation failed.org.hibernate.MappingException: An association from the table backlogaufgabe refers to an unmapped class: int " will be shown with this mapping:
<hibernate-mapping package="app.domain">
<class mutable="false" name="app.domain.BacklogAufgabe" table="backlogaufgabe">
<composite-id class="BacklogAufgabe$Id" name="id">
<key-property access="field" column="id_backlog" name="backlogId"/>
<key-property access="field" column="id_aufgabe" name="aufgabeId"/>
<key-property access="field" column="revision" name="revisionId"/>
</composite-id>
<property column="datum" name="datum" not-null="t开发者_开发知识库rue" type="date"/>
<property column="rang" name="rang" not-null="true" type="int"/>
<property column="revision" name="revision" not-null="true" type="int"/>
<property column="aufw_schaetzung" name="aufwSchaetzung" not-null="true" type="int"/>
<property column="aufw_messung" name="aufwMessung" not-null="true" type="int"/>
<many-to-one cascade="save-update" column="id_aufgabe" insert="false" lazy="false"
name="aufgabe" not-null="true" update="false"/>
<many-to-one cascade="save-update" column="id_backlog" insert="false" lazy="false"
name="backlog" not-null="true" update="false"/>
<many-to-one cascade="save-update" column="revision" insert="false" lazy="false"
name="revision" not-null="true" update="false"/>
</class>
</hibernate-mapping>
SQL:
CREATE TABLE backlogaufgabe
(
id serial NOT NULL,
id_backlog integer NOT NULL,
id_aufgabe integer NOT NULL,
revision integer NOT NULL,
datum date NOT NULL,
rang integer NOT NULL,
aufw_schaetzung integer,
aufw_messung integer,
CONSTRAINT backlogaufgabe_pkey PRIMARY KEY (id),
CONSTRAINT backlogaufgabe_id_aufgabe_fkey FOREIGN KEY (id_aufgabe)
REFERENCES aufgabe (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE RESTRICT,
CONSTRAINT backlogaufgabe_id_backlog_fkey FOREIGN KEY (id_backlog)
REFERENCES backlog (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE RESTRICT
)
WITH (
OIDS=FALSE
);
You should try to put revision as a primary key while creating your table. Because as I've notice on the mapping file you didn't mentioned the ID
that was already a primary key, and instead you added revision as a primary key which is not the case on the real table. If you see what I mean. So maybe you should put revision as primary key instead of the id.
Try this:
CREATE TABLE backlogaufgabe
(
id_backlog integer NOT NULL,
id_aufgabe integer NOT NULL,
revision integer NOT NULL,
datum date NOT NULL,
rang integer NOT NULL,
aufw_schaetzung integer,
aufw_messung integer,
CONSTRAINT backlogaufgabe_pkey PRIMARY KEY (revision),
CONSTRAINT backlogaufgabe_id_aufgabe_fkey FOREIGN KEY (id_aufgabe)
REFERENCES aufgabe (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE RESTRICT,
CONSTRAINT backlogaufgabe_id_backlog_fkey FOREIGN KEY (id_backlog)
REFERENCES backlog (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE RESTRICT
)
WITH (
OIDS=FALSE
);
精彩评论