Hi,
I have class with auto relationship represented by a list of childs in my class and represented by a parent foreign key in my database table. Is possible to do this? The informations had been saved in database but the parent foreign key and index columns are null.
table:
CREATE TABLE message (
id BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1, INCREMENT BY 1) PRIMARY KEY,
subject VARCHAR NOT NULL,
message VARCHAR NOT NULL,
date TIMESTAMP NOT NULL,
parent_fk BIGINT,
index INTEGER,
FOREIGN KEY ( parent_fk ) REFERENCES message ON DELETE CASCADE
);
Class attributes:
public class Message implements Serializable {
private Long id;
private String subject;
private String message;
private Date date;
private List<Message> childMessages;
// i show only the attributes here
...
}
Mapping documents:
<hibernate-mapping>
<class name="Message" table="message">
<id name="id">
<generator class="native"/>
</id>
<property name="subject"/>
<property name="message"/>
<property name="date" type="timestamp"/>
<list name="childMessages" cascade="all" inverse="true" >
<key column="parent_fk"/>
<list-index column="index"/>
<one-to-many class="Message"/>
</list>
</class>
</hibernate-mapping>
Thanks for all,
Claudio Escobar Apparicio
|