Question: I'm working on a Grails application where I need to integrate with an existing database (Oracle) that uses GUIDs as primary keys on certain tables. Grails is able to easily handles this using:

```
static mapping = {
    id generator: 'guid'
}

```

My issues comes in when I'm trying to write some **integration tests** using an in memory database. Is there an in memory database that supports GUID primary key columns? If not is there a way to switch the generator value during test?

So far I have tested the default H2 database provided by Grails with no luck.

Answer: 
It looks like Hibernate's GUID support is really just there to wrap Oracle's implementation, so it's not portable and won't work with H2. But it's simple enough to use your own that works everywhere. Implement the `org.hibernate.id.IdentifierGenerator` interface, e.g.

```
package com.mycompany.myapp

import org.hibernate.engine.SessionImplementor
import org.hibernate.id.IdentifierGenerator

class UuidIdentifierGenerator implements IdentifierGenerator {

   Serializable generate(SessionImplementor session, object) {
      UUID.randomUUID().toString()
   }
}

```

and change the generator attribute to be the full class name of your implementation:

```
class MyDomainClass {
   String id
   // other fields

   static mapping = {
      id generator: 'com.mycompany.myapp.UuidIdentifierGenerator'
   }
}

```
I use Hibernate hbm mapping in this way:

```
<id  name="id" column="id" >
    <generator class="guid"></generator>
</id>

```