-->
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.  [ 1 post ] 
Author Message
 Post subject: Hibernate mapping Problem
PostPosted: Sat May 22, 2010 10:35 am 
Newbie

Joined: Sat May 22, 2010 10:32 am
Posts: 3
Hi,

There is a table Item like,

Code:
code,name
01,parent1
02,parent2
0101,child11
0102,child12
0201,child21
0202,child22


Create a java object and hbm xml to map the table.The Item.parent is a Item whose code is equal to the first two characters of its code :
Code:
class Item{
    String code;
    String name;
    Item parent;
    List<Item> children;

    .... setter/getter....

}


Code:
<hibernate-mapping>
    <class name="Item" table="Item">
        <id name="code" length="4" type="string">
            <generator class="assigned" />
        </id>
        <property name="name" column="name" length="50" not-null="true" />

    <many-to-one name="parent" class="Item" not-found="ignore">
        <formula>
        <![CDATA[
        (select i.code,r.name from Item i where (case length(code) when 4 then i.code=SUBSTRING(code,1,2) else false end))
        ]]>
        </formula>
    </many-to-one>

        <bag name="children"></bag>
    </class>

</hibernate-mapping>


I try to use formula to define the many-to-one&bag relationship,but it doesn't work!Is there something wrong?Or is there other method?

Thanks!

ps,I use mysql database.


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

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.