Hibernate 在我的数据库中随机生成 joda 时间列作为小 blob
我遇到了一些奇怪的情况,我似乎无法弄清楚。
我有一组 Hibernate 带注释的实体类,其中包含 Jodatime 日期时间字段。当 hibernate 生成我的架构时,一些日期时间字段被正确设置为 MySQL 中的 DateTime 列,而其他字段则被创建为微小的 blob。我正在使用 Usertype 库为我进行类型映射,但我已经使用 joda-time-hibernate 库尝试过,并且得到了相同的结果。奇怪的是,这些列在我的代码中声明的方式都是相同的,例如,
这个列生成一个小斑点而不是日期时间:
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime respondedTime;
但是另一个类中的这个列正确生成日期时间列:
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime date;
所以我是想知道是否有人经历过类似的事情,或者他们是否知道如何确保 Hibernate 为我的日期时间字段生成日期时间列。
如果有什么区别,我正在使用 usertype 版本 1.8 和 jodatime 版本 1.6 以及 hibernate 3.6.0.Final
I have a bit a of an odd situation happening and I can't seem to figure it out.
I have a set of Hibernate annotated entity classes that have Jodatime date time fields on them. When hibernate generates my schema some of the date time fields are set up correctly as DateTime columns in MySQL and others are created as tiny blobs. I am using the Usertype library to do my type mapping for me but I have tried it with the joda-time-hibernate library and I get the same result. The weird thing is that these columns are all identical in the way they are being declared in my code e.g.
This one generates a tiny blob instead of a date time:
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime respondedTime;
But this one in a different class generates a date time column correctly:
@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
private DateTime date;
So I was wondering if anybody has experienced something similar happen to them or if they know how to ensure that Hibernate generates DateTime columns for my datetime fields.
If it makes any difference I am using usertype version 1.8 and jodatime version 1.6 with hibernate 3.6.0.Final
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 Hibernate 无法找到列的用户类型,或者当
UserType
实现认为它无法处理该类型时,就会发生此行为。因此,要么参数上有类型,要么
UserType
中存在错误,或者DateTime
在这两个地方是不同的类型。为了避免拼写错误,我建议使用
@TypeDefs
为用户类型创建更易读的名称。请参阅这篇博文。
This behavior happens if Hibernate can't find the user type for a column or when the
UserType
implementation thinks it can't handle the type.So either there is a type on the parameter or there is a bug in the
UserType
orDateTime
is a different type in the two places.To avoid typos, I suggest to use
@TypeDefs
to create more readable names for user types.See this blog post.
正如 @jthalbom 在评论中提到的,这原来是一个类路径问题。我清理了加载到类路径上的罐子,瞧,问题解决了!
As @jthalbom mentioned in the comments this turned out to be a classpath issue. I cleaned up the jars that were loaded onto my classpath and voila, problem solved!