Home How should implement one to many mapping in GORM as List
Reply: 1

How should implement one to many mapping in GORM as List

Madhvendra Thakur
1#
Madhvendra Thakur Published in 2017-12-04 17:52:19Z

Domain Listini and Durate:

<class name="Listino" table="listini"> 
    <id column="id" name="id" type="int" unsaved-value="null">
        <generator class="sequence">
            <param name="sequence">listini_seq</param>
        </generator>
    </id>
    <list cascade="all-delete-orphan" name="durate" table="durate">
        <cache usage="read-write"/>
        <key column="id_listino"/>
        <list-index column="index"/>
        <one-to-many class="Durata"/>
    </list>
</class>

<class name="Durata" table="durate">
    <id column="id" name="id" type="int" unsaved-value="null">
        <generator class="sequence">
            <param name="sequence">durate_seq</param>
        </generator>
    </id>
    <many-to-one class="Listino" column="id_listino" name="listino"/>
</class>

I have two domain, and I was using Hibernate hbm file, but now I have to convet this mapping with GORM domain.

Please suggest me that how to implement this mapping with GORM, I need the same mapping means, I need list index and the data must be store as a List.

elixir
2#
elixir Reply to 2017-12-05 18:23:50Z

Here is a basic schema to start with.

class Listino{

    // id is automatically handled by grails
    ...

    static hasMany = [durate : Durata]


    static mapping = {
        table "listini"
    }
}


class Durata{

    // id is automatically handled by grails
    ...

    Listino listino    // this create a belongs to relationship


    static mapping = {
        table "durate"
    }
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301957 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO