1
現在,我有以下的屬性域對象之一:java.awt.Color中的映射在Hibernate中
@Column(name = "color")
public Color getColor() {
return color;
}
字段中,儲存在Postgres的DB文本。當我嘗試存儲這些時,我得到以下例外:
org.hibernate.type.SerializationException: could not deserialize
at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:243)
at org.hibernate.internal.util.SerializationHelper.deserialize(SerializationHelper.java:287)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.fromBytes(SerializableTypeDescriptor.java:138)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:113)
at org.hibernate.type.descriptor.java.SerializableTypeDescriptor.wrap(SerializableTypeDescriptor.java:27)
at org.hibernate.type.descriptor.sql.VarbinaryTypeDescriptor$2.doExtract(VarbinaryTypeDescriptor.java:53)
at ...
Caused by: java.io.StreamCorruptedException: invalid stream header: 5C786163
at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
at java.io.ObjectInputStream.<init>(Unknown Source)
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:309)
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.<init>(SerializationHelper.java:299)
at ...
我想知道Hibernate是否提供這種類型的映射?我有的另一種可能性是使用RGB值將Color轉換爲字符串。但是因爲我的域對象也是我的Hibernate對象,所以我不知道如何在不將屬性類型更改爲String的情況下做到這一點。