使用@ElementCollection,@ CollectionTable和LocalDate进行序列化问题

时间:2018-04-18 20:41:43

标签: java spring jpa serialization jodatime

我在Java 8 + Spring + Lombok项目中遇到了一些序列化问题。这些是我的课程:

Operation.java

public classe Operation 
{

@Id
@GeneratedValue
@Getter
@Setter(AccessLevel.PUBLIC)
@Access(AccessType.PROPERTY)
private Long id;

@NonNull
@NotEmpty
private String name;

...

@ElementCollection(targetClass = Period.class, fetch = FetchType.EAGER)
@CollectionTable(name = "operation_period", joinColumns = @JoinColumn(name = "operation_id"))
@OrderBy("start DESC")
private List<Period> periods = new ArrayList<Period>();

}

Period.java

@Data
@NoArgsConstructor
@Embeddable
public class Period implements Serializable 
{

private static final long serialVersionUID = 8749871604855032518L;

@NonNull
@NotNull
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate start;

@NonNull
@NotNull
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate end;

每当我尝试使用JPQL查询我的数据库时,我都会遇到这样的异常:

java.io.StreamCorruptedException: invalid stream header: 32303135
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:328)
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:318)
at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:237)
at org.hibernate.internal.util.SerializationHelper.deserialize(SerializationHelper.java:306)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.fromBytes(SerializableTypeDescriptor.java:155)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:130)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:44)
at org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor$2.doExtract(VarbinaryTypeDescriptor.java:70)
at org.hibernate.type.descriptor.sql.BasicExtractor.extract(BasicExtractor.java:64)

我无法找到我的映射有什么问题。 有人可以帮帮我吗?

0 个答案:

没有答案