我正在学习如何使用Spring访问数据库。
我编写了一个包含速溶字段的实体应用程序:
@Entity
@Table(
name = "MEAL",
uniqueConstraints=@UniqueConstraint(columnNames = {"USER_ID", "TIMESTAMP_FIELD"}))
public class Meal {
//private static DateTimeZone defaultTimeZone = DateTimeZone.UTC;
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
@Column(name = "ID")
private long id;
@ManyToOne//(fetch=FetchType.LAZY)
@JoinColumn(name="USER_ID")
private User user;
// @Temporal(TemporalType.TIMESTAMP) if non-Joda time
//@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentDateTime")
@Column(name = "TIMESTAMP_FIELD")
private Instant timestampField;我无法用@Temporal或@Type注释编译/运行它们,因此它们被注释掉了。
此外,我无法在application.properties中设置application.properties时运行。
它造成了一个错误
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.registerTypeOverride(Lorg/hibernate/usertype/UserType;[Ljava/lang/String;)Lorg/hibernate/cfg/Configuration;因此,这一行也被注释掉了。
spring.datasource.url=jdbc:h2:tcp://localhost/~/pdk
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driver-class-name=org.h2.Driver
# Jadira requirement
#spring.jpa.properties.jadira.usertype.autoRegisterUserTypes=true不幸的是,在最后的状态下,我得到了一些字段内容中的序列化/二进制数据。

这里是否可能有一些与SQL兼容的列类型?
更新
我发现,以下注释运行良好:
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentInstantAsTimestamp")但是为什么在application.properties中设置不起作用呢?
发布于 2016-01-12 13:55:57
偶然发现了同样的问题,结果发现Jadira的版本(5.0.0.GA)与Hibernate 4.xSPI不兼容。
切换到4.0.GA完成了这个任务,并且使用jadira.usertype.autoRegisterUserTypes=true注册Jadira的类型开始工作。
https://stackoverflow.com/questions/34454453
复制相似问题