-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Auto relationship using a list
PostPosted: Thu Jul 05, 2007 4:17 pm 
Newbie

Joined: Mon Dec 12, 2005 12:38 pm
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 06, 2007 9:03 am 
Newbie

Joined: Mon Dec 12, 2005 12:38 pm
Posts: 3
I'm thinking in remove the relationship of List<Message> and insert a Message parentMessage relationship in hbm. The childMessages list will be mapped to a formula search.
But i don't know how i do this query, because i need the order, and the date is fragile....

Class attributes:

public class Message implements Serializable {

private Long id;
private String subject;
private String message;
private Date date;
private Message parentMessage;
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"/>
<property name="parentMessage">
<formula>
SQL
</formula>
</property>

<many-to-one name="parentMessage" column="parent_fk" class="Message"/>

</class>
</hibernate-mapping>

Thanks for all

_________________
Claudio Escobar Apparicio


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.