Home How to implement Identity generator with groovy domain
Reply: 1

How to implement Identity generator with groovy domain

Madhvendra Thakur
1#
Madhvendra Thakur Published in 2018-02-13 12:07:58Z

I have to create groovy domain using the hibernate mapping file, Here I'm writing the hibernate mapping file, I do not know that how to use identity generator in groovy and also there is a many to one mapping with UserImpl Please help to create a groovy domain

<hibernate-mapping>
<class name="User" table="user">

    <id name="id" column="id" type="java.lang.Long">
        <generator class="identity"/>
    </id>
    <property column="password" name="password" type="java.lang.String" />
    <property column="data_inserimento" name="dataInserimento" 
    type="java.util.Date" not-null="true" />
    <property column="giorni_validita" name="giorniValidita" type="int" not-
     null="true"/>
    <properties name="ultimaPassword">
        <many-to-one class="UserImpl" column="id_utente" 
        name="utente"/>
        <property name="ultima" type="java.lang.Boolean"/>
    </properties>

 </class>
 </hibernate-mapping>
Mamun Sardar
2#
Mamun Sardar Reply to 2018-02-19 14:19:11Z

Assuming you are on grails latest (3.3.2) version, the default identity name is id and use mapping for generator, for example:

class MyDomain {
    Long id //will be treated as id
    static mapping {
        id generator: 'identity'
    }
}

For more details checkout Grails mapping doc and GORM custom id doc

From docs:

generator (optional) - The name of the generator to use. Can be increment, identity, sequence, seqhilo, uuid, uuid.hex, assigned, select, foreign, sequence-identity, enhanced-sequence or enhanced-table

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO