开发者

Hibernate is randomly generating joda time columns in my database as tiny blobs

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 ge开发者_如何学Cnerates 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


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 or DateTime 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.


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜