Hibernate custom UserType isn't working

前端 未结 3 813

I\'ve created a UserType (see below) to handle a situation in our mySQL database where we\'ve been saving null dates as 0000-00-00 00:00:00.

When I try and persist m

相关标签:
3条回答
  • 2021-01-12 18:37

    These nuances are quite well discussed here: http://blog.xebia.com/2009/11/09/understanding-and-writing-hibernate-user-types/

    0 讨论(0)
  • 2021-01-12 18:44

    Your problem is not with your UserType - it's with the fact that you've declared your property as not-null (using @Basic optional="false") and yet you're setting it to null.

    That said, I'd be careful about returning the original value in deepCopy / assemble / disassemble methods. java.util.Date is mutable and you may be asking for trouble there.

    0 讨论(0)
  • 2021-01-12 19:03

    Ready and working solution for DATE and TIME: How to map MySQL DATE '0000-00-00' & TIME '00:00:00' with Hibernate

    Thanks Preston for the code and ChssPly76 for useful comments.

    0 讨论(0)
提交回复
热议问题