我正在使用UserType 3.2.0-GA,Hibernate 4.3.8,与AWS(RDS)上现有的mysql实例交谈。
我正在尝试从Hibernate 3.2.6和joda-time-hibernate 1.1升级应用程序。
失败的财产:
import org.joda.time.LocalDate;
...
public LocalDate getBirthdate() {
return this.birthdate;
}
模特:
org.hibernate.type.SerializationException: could not deserialize (Caused by: java.io.StreamCorruptedException: invalid stream header: 31393936)
org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:262)
org.hibernate.internal.util.SerializationHelper.deserialize(SerializationHelper.java:306)
org.hibernate.type.descriptor.java.SerializableTypeDescriptor.fromBytes(SerializableTypeDescriptor.java:155)
org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:130)
org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:44)
org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor$2.doExtract(VarbinaryTypeDescriptor.java:71)
org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)
org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:267)
org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:263)
org.hibernate.type.AbstractStandardBasicType.nullSafeGet(AbstractStandardBasicType.java:253)
org.hibernate.type.AbstractStandardBasicType.hydrate(AbstractStandardBasicType.java:338)
...
java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:804)
尝试读取现有数据时出错:
WARN: SQL Error: 1292, SQLState: 22001
Apr 12, 2016 5:12:07 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: Data truncation: Incorrect date value: '��' for column 'birthdate' at row 1
Apr 12, 2016 5:12:07 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper$StandardWarningHandler logWarning
WARN: SQL Warning Code: 1292, SQLState: HY000
Apr 12, 2016 5:12:07 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper$StandardWarningHandler logWarning
WARN: Incorrect date value: '��' for column 'birthdate' at row 1
尝试写入新数据时出错:
org.springframework.dao.DataIntegrityViolationException: could not execute statement; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not execute statement
<bean id="hibernateProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="properties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.EhCacheRegionFactory</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
</props>
</property>
</bean>
正如您所看到的,我正在使用Spring来配置内容。我在春天的hibernate属性是:
<body>
<S1 A="1">
<S2 B="1">
<S3 C="1"/>
<S3 C="1"/>
</S2>
<S2 B="2"/>
</S1>
<S1 A="2"/>
答案 0 :(得分:1)
原来我通过将类型设置为:
来实现它 <property name="birthdate" not-null="true" type="org.jadira.usertype.dateandtime.joda.PersistentLocalDate"/>
不幸的是,我不明白为什么这样做或者甚至是必要的。更多的解释会很棒。