Grails Mapping LocalDateTime of Java 8 domain objects to Gorm

让人想犯罪 __ 提交于 2020-01-16 04:50:09

问题


Java 8 gives the java.time API.

I am using a grails application, I want to use java.time for properties of my domain classes.

I need to map for instance the LocalDateTime to the DATE/DATETIME on GORM which is built on top of Hibernate.

How can I persist my mappings?

I see a solution, that I can use jadira, and establish static mappings for my attributs.

However is there another way?

Please any help is appreciated.


回答1:


You can use the user type mapping. See the docs. That should remove the need to explicitly map all instances individually.

To go further, I would take the grails-joda-time plugin sources and try to make a jave.time version. And even try to make (and submit a pull request) a version that would support both joda-time and java.time.




回答2:


I haven't used gorm, but if we were to speak hibernate only (and I guess that it should be applicable), you would be able to follow two path.

One, if you are using or if you're able to upgrade to hibernate 5, than you can include the hibernate-java8

Support for using Java8 specific data-types such as any of the JSR 310 Date/Time types in domain model.

Otherwise, you would have to write your own type as explained here, and use it e.g. like

@Type(type="your.custom.LocalDateTimeUserType")
private LocalDateTime date;

Finally, gorm is implementing the JPA specification, you can implement a converter



来源:https://stackoverflow.com/questions/35507996/grails-mapping-localdatetime-of-java-8-domain-objects-to-gorm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!