我遇到了将postgresql类型映射到时区'时间戳的问题。在java.time.LocalDateTime上。我正在使用:postgresql,dropwizard with hibernate。
表:
@Override
public void zzm(Intent intent) {
Log.e(TAG, "zzm : " + intent);
createBigPictureNotification();
}
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
}
核心:
CREATE SEQUENCE "auth"."roles_seq_id";
CREATE TABLE "auth"."roles" (
id BIGINT NOT NULL DEFAULT nextval('auth.roles_seq_id'),
name VARCHAR(50) NOT NULL,
createdat TIMESTAMP WITH TIME ZONE DEFAULT now() NOT NULL
);
ALTER TABLE "auth"."roles" ADD CONSTRAINT "roles_id_pk" PRIMARY KEY (id);
错误:
错误[2017-07-21 08:13:43,465] io.dropwizard.jersey.errors.LoggingExceptionMapper:处理错误 请求:b09a66b06dd214bd ......!曹景伟: org.hibernate.type.SerializationException:无法反序列化
的pom.xml:
import lombok.*;
import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;
@Getter
@Setter
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(schema = "auth", name = "roles")
public class Role implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "roles_id_generator")
@SequenceGenerator(name = "roles_id_generator", sequenceName = "roles_seq_id")
@Column(name = "id")
private Long id;
@NonNull
@Column(name = "name", nullable = false)
private String name;
@Column(name = "createdat")
private LocalDateTime createdAt;
}
当我删除<dropwizard.version>1.0.6</dropwizard.version>
<postgresql.version>9.4.1212</postgresql.version>
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-hibernate</artifactId>
<version>${dropwizard.version}</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>${postgresql.version}</version>
</dependency>
或使用createdAt
(但我想使用LocalDateTime)时,一切正常。
答案 0 :(得分:2)
似乎dropwizard-hibernate:1.0.6
捆绑了Hibernate 5.1。根据{{3}},需要额外的依赖关系来支持java.time
类型:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-java8</artifactId>
<version>5.1.0.Final</version>
</dependency>
此外,从Hibernate 5.2开始,不需要这种额外的依赖性,似乎功能被折叠到主要依赖项中。