Custom gridtypes howto

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)

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

Please advice.

Best regards

Andy

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
  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 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

Hi DavideD,

Thank you very much for your reply.

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

Best regards

Andy