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: formula : parent...recursive
PostPosted: Tue May 12, 2009 6:19 am 
Newbie

Joined: Tue May 12, 2009 5:54 am
Posts: 9
Hi,
i've a problem
i want write a property element Chemin with a formula
Code:
    <class
        name="Niveau, Core"
        table="NIVEAU"

        <id name="Id" type="Int64" unsaved-value="null">
            <column name="ID" sql-type="BIGINT"/>
            <generator class="assigned">
            </generator>
        </id>

        <many-to-one name="NiveauParent" class="Niveau, Core" outer-join="auto" cascade="none" foreign-key="NIVEAU_NIVEAU_PARENT_FKC">
            <column name="NIVEAU_PARENT_FK" not-null="false" sql-type="BIGINT"/>
        </many-to-one>

        <property name="Chemin" type="String" formula="??????" />

</class>


For example :

niveau1.NiveauParent= null
niveau1.ID = 0

niveau2.NiveauParent= niveau1
niveau2.ID= 1

niveau3.NiveauParent= niveau2
niveau3.ID = 1

I wish :

niveau1.Chemin = "0"
niveau2.Chemin = "0-1"
niveau3.Chemin = "0-1-2"

I try use annotation

<property name="Chemin" type="String" formula="(case when (NIVEAU_PARENT_FK IS null) then
ID
else
(select ID + '-' + __niveau.CHEMIN from NIVEAU as __niveau where __niveau.id=NIVEAU_PARENT_FK)
end)" />
but It dosn't work
Remarks : max deep = 3
How should do this ?

Thanks for helping


Top
 Profile  
 
 Post subject: Re: formula : parent...recursive
PostPosted: Tue May 12, 2009 10:50 am 
Newbie

Joined: Tue May 12, 2009 5:54 am
Posts: 9
Code:
<property name="Chemin" type="String" formula="(case when (NIVEAU_PARENT_FK IS null) then
               ID
               else
              (case when ((select __NIVEAU.NIVEAU_PARENT_FK from NIVEAU as __NIVEAU where __NIVEAU.id=NIVEAU_PARENT_FK) is null)
                    then (ID + '-' + NIVEAU_PARENT_FK)
                    else (select (ID + '-' +  NIVEAU_PARENT_FK + '-' + __NIVEAU.NIVEAU_PARENT_FK) from NIVEAU as __NIVEAU where __NIVEAU.id=NIVEAU_PARENT_FK) end)
               
                 end)" />

i've problem, beacause (ID + '-' + NIVEAU_PARENT_FK) -> 3 and not "1-2". Why ? I try to convert but ....


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.