-->
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.  [ 7 posts ] 
Author Message
 Post subject: bidirectionnal one-to-many on the same Class : design issue
PostPosted: Mon Nov 17, 2003 2:39 pm 
Newbie

Joined: Tue Oct 28, 2003 5:35 am
Posts: 7
I've read many threads into this forum talking about parent/child association but I didn't find any real answer about the following mapping issue :

Here is the association I want to map :

Code:
   Task -- (0,n) ---> [subtask_association] <--- (1,1) Task



which means :
    * a Task may have 0,n sub-tasks (but a sub-task is a Task)
    * a subTask has always access to its parent Task.

Based on what I've read, this is pretty easy if the cardinality between a subTask and its parent Task is (0,1). In this case, a foreign key "parentTask" can easily be added to Task class to get a fully bidirectionnal one-to-many association.

However, in my case, I want from a subtask to be able to get the parent Task (cardinality 1,1) referenced into the entity table ....

but there's no way to specify a table name into a "many-to-one or a one-to-one" association.

Is my approach completely wrong ?
Any clue ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 2:45 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
What you need is a many-to-one not-null="true" and a DB having a not null constraint on it.
But what about RootTask ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 7:01 pm 
Newbie

Joined: Tue Oct 28, 2003 5:35 am
Posts: 7
epbernard wrote:
What you need is a many-to-one not-null="true" and a DB having a not null constraint on it.
But what about RootTask ?


What is a RootTask for u ? coming back to your comment, the many-to-one association with not-null="true" can only (tell me if i'm wrong) be done a column of the Task class.

What I would like (but may be you have a better approach) is to map from the Task class a one-to-many association to the "association" entity class between Task and Task. Is it more clear or am I confusing you ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 7:06 pm 
Newbie

Joined: Tue Oct 28, 2003 5:35 am
Posts: 7
philippe wrote:
epbernard wrote:
What you need is a many-to-one not-null="true" and a DB having a not null constraint on it.
But what about RootTask ?


What is a RootTask for u ? coming back to your comment, the many-to-one association with not-null="true" can only (tell me if i'm wrong) be done a column of the Task class.

What I would like (but may be you have a better approach) is to map from the Task class a one-to-many association to the "association" entity class between Task and Task. Is it more clear or am I confusing you ?


Ok ... sorry ... I've just understand your question : "but what about the RootTask ?" ... and this is exactly my problem :

    * there's a one-to-many association from Task to itself.
    * The RootTask has a one-to-many assocation to itself, the cardinality being (0,n) AND that's the issue !
    * It means that the RootTask can't have any parent (or maybe itself)
    * a sub-task has a mandatory parent Task (1,1 cardinality)


I think we have the same understanding of the problem.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 7:44 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Well, I don't have a magic solution ;-(
I've never try to reference a "root" row having a not null constaint and a FK to itself. I don't think the DB allows that.

A better approch may be to add some Lifecycle or some interceptor in hibernate to check the cardinality and manage the root case.

Any other ideas ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 17, 2003 8:03 pm 
Newbie

Joined: Tue Oct 28, 2003 5:35 am
Posts: 7
epbernard wrote:
Well, I don't have a magic solution ;-(
I've never try to reference a "root" row having a not null constaint and a FK to itself. I don't think the DB allows that.

A better approch may be to add some Lifecycle or some interceptor in hibernate to check the cardinality and manage the root case.

Any other ideas ?

Thanks Emmanuel for your ideas ; managing it via an Interceptor or a Lifecycle is clever ; I will try a proof-of-concept in this way.

My only concern is that I thought that this kind of mapping is a common one and that Hibernate offers a simple mapping solution for it but that's not the case.

In fact, Object mapping with Hibernate for a newbie is not so trivial and I will say that the only concern with Hibernate documentation I have is that it's really dedicated to users already knowing Object mapping concepts ... :-((

Anyway, thanks for you help, any other ideas guys ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 9:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
philippe wrote:
the only concern with Hibernate documentation I have is that it's really dedicated to users already knowing Object mapping concepts

When I started with Hibernate, I was kind of a rookie on O/R mapping. After reading the doc several times and analysing every single word of it, I learnt a lot.
Using this kind of tools wo knowledge is like using JDBC wo knowing SQL, you make architecture and design issues.
This is a vicious circle, but it can become a virtuous one with work.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.