# Custom gridtypes howto

**URL:** <https://discourse.hibernate.org/t/custom-gridtypes-howto/513>\
**Category:** Hibernate OGM\
**Created:** [April 6, 2018, 8:40am UTC](https://discourse.hibernate.org/t/custom-gridtypes-howto/513 "2018-04-06T08:40:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![HkGlF1](https://avatars.discourse-cdn.com/v4/letter/h/f17d59/32.png) [@HkGlF1](https://discourse.hibernate.org/u/HkGlF1)\
**Post date:** [April 6, 2018, 8:40am UTC](https://discourse.hibernate.org/t/custom-gridtypes-howto/513/1 "2018-04-06T08:40:40Z")

</div>

I have found many, many guides to implementing a custom usertype in Hibernate ORM, but when it comes to OGM, the web is almost silent.

I trying to convert a simple project from using a MySQL backend to using Neo4j.

I’m using the latest release of Hibernate OGM (5.3.1).

In my current implementation i have a UserType mapping LocalDateTime and other customer objects to columns in MySQL - works great.

However having moved to OGM, I not get errors like:  
Caused by: org.hibernate.HibernateException: OGM000059: Unable to find a GridType for LocalDateTime

How do I correctly handle custom objects like LocalDateTime objects (and other custom objects) in Hibernate OGM?

I have searched for custom GridType and the only example I found pointed me to MongoDBTypeContributor.  
([https://github.com/hibernate/hibernate-ogm/blob/master/mongodb/src/main/java/org/hibernate/ogm/datastore/mongodb/type/impl/MongoDBTypeContributor.java](https://github.com/hibernate/hibernate-ogm/blob/master/mongodb/src/main/java/org/hibernate/ogm/datastore/mongodb/type/impl/MongoDBTypeContributor.java))

But I’m having trouble to translate this to my problem.

Please advice.

Best regards

Andy

---

<div class="post-metadata">

**Author:** ![DavideD](https://avatars.discourse-cdn.com/v4/letter/d/48db29/32.png) [@DavideD](https://discourse.hibernate.org/u/DavideD)\
**Post date:** [April 6, 2018, 11:24am UTC](https://discourse.hibernate.org/t/custom-gridtypes-howto/513/2 "2018-04-06T11:24:36Z")

</div>

At the moment there is not a mechanism similar to ORM for custom grid types in OGM.  
Depending on the use case, there are 3 ways to add custom types at the moment:

1. With a TypeContributor like in the example you have already found
2. with an AttributeConverter, an example is here: [https://github.com/hibernate/hibernate-ogm/blob/master/core/src/test/java/org/hibernate/ogm/backendtck/type/converter/Printer.java](https://github.com/hibernate/hibernate-ogm/blob/master/core/src/test/java/org/hibernate/ogm/backendtck/type/converter/Printer.java)
3. You can extends the base dialect and override the method public `GridType overrideType(Type type)`. You can see an example in this test where it ovverides the method extending MapDialect: [https://github.com/hibernate/hibernate-ogm/blob/master/core/src/test/java/org/hibernate/ogm/test/type/converter/JpaAttributeConverterGridTypeApplicationTest.java#L89](https://github.com/hibernate/hibernate-ogm/blob/master/core/src/test/java/org/hibernate/ogm/test/type/converter/JpaAttributeConverterGridTypeApplicationTest.java#L89) Make sure to use your new dialect class by setting the property `hibernate.ogm.datastore.grid_dialect` with the name of the class

I hope this helps,  
Davide

---

<div class="post-metadata">

**Author:** ![HkGlF1](https://avatars.discourse-cdn.com/v4/letter/h/f17d59/32.png) [@HkGlF1](https://discourse.hibernate.org/u/HkGlF1)\
**Post date:** [April 9, 2018, 7:27pm UTC](https://discourse.hibernate.org/t/custom-gridtypes-howto/513/3 "2018-04-09T19:27:36Z")

</div>

Hi DavideD,

Thank you very much for your reply.

Suggestion no. 2 was the way to go for me.

Best regards

Andy
