0
我正在嘗試爲泰坦圖編寫一個自定義java.util.Date序列化器。這裏是我的泰坦配置文件:在titan圖中配置自定義屬性序列化器時發生java.lang.IllegalStateException
attributes.allow-all = true
attributes.custom.attribute1.attribute-class = java.util.Date
attributes.custom.attribute1.serializer-class = com.serializer.MyDateSerializer
和我的串行的樣子:
public class MyDateSerializer implements AttributeSerializer<Date> {
@Override
public void verifyAttribute(Date value) {
// TODO Auto-generated method stub
}
@Override
public Date convert(Object value) {
// TODO Auto-generated method stub
return null;
}
@Override
public Date read(ScanBuffer buffer) {
// TODO Auto-generated method stub
}
@Override
public void write(WriteBuffer buffer, Date date) {
// TODO Auto-generated method stub
}
}
但打開TitanGraph後,我收到以下異常:
java.lang.IllegalStateException: Need to set configuration value: root.attributes.custom.serializer-class
at com.google.common.base.Preconditions.checkState(Preconditions.java:177)
at com.thinkaurelius.titan.diskstorage.configuration.ConfigOption.get(ConfigOption.java:158)
at com.thinkaurelius.titan.diskstorage.configuration.BasicConfiguration.get(BasicConfiguration.java:56)
at com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.<init>(GraphDatabaseConfiguration.java:1334)
at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:91)
at com.thinkaurelius.titan.core.TitanFactory.open(TitanFactory.java:71)
這裏是如何我試圖從屬性文件中讀取配置:
BaseConfiguration configuration = new BaseConfiguration();
Properties properties = new Properties();
properties.load(getClass().getResourceAsStream(
"/titanConfiguration.properties"));
Set<Entry<Object, Object>> entrySet = properties.entrySet();
for (Entry<Object, Object> entry : entrySet) {
configuration.setProperty(entry.getKey().toString(), entry
.getValue().toString());
}
我已經通過了0.5.2版本的泰坦圖形文檔,但Iam無法找出問題所在。我也經歷了類似的帖子,但我仍然無法解決這個問題。有沒有人遇到過這個問題?
如果我試圖堅持巨頭頂點內java.util.Date如下:
vertex.setProperty("myDate",new Date());
,然後當我嘗試從頂點檢索日期爲:
((Date)vertex.getProperty("myDate"));
我得到以下例外情況:
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Date
at org.rampal.Transaction.getUsers(Transaction.java:179)
at org.rampal.Controller.getUsers(Controller.java:71)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
感謝您的答覆。當我將日期保存到頂點(vertex.setProperty(「date」,new Date()))時,獲取的日期是classcast異常,說明java.lang.String不能轉換爲java.util.Date。這就是爲什麼我有動力編寫一個序列化程序。任何想法在直接在頂點中保存新的Date()時會出現什麼問題? – user3244615 2015-03-09 11:39:04
你有堆棧跟蹤嗎? – Bryn 2015-03-09 13:44:15
我已經用堆棧跟蹤更新了帖子 – user3244615 2015-03-10 08:01:09