我認爲,這將是罰款分享從詹姆斯的回答得到的完整的解決方案。
首先,創建一個DescriptorCustomizer
implmentation:
import org.eclipse.persistence.config.DescriptorCustomizer;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.mappings.xdb.DirectToXMLTypeMapping;
public class XMLDataCustomizer implements DescriptorCustomizer {
public void customize(final ClassDescriptor descriptor) throws Exception {
descriptor.removeMappingForAttributeName("xmlField");
DirectToXMLTypeMapping mapping = new DirectToXMLTypeMapping();
mapping.setAttributeName("xmlField"); //name of the atribute on the Entity Bean
mapping.setFieldName("XML_COLUMN"); //name of the data base column
descriptor.addMapping(mapping);
}
}
然後,所有你需要做的就是使用@Customizer
anotation的實體,爲EntityManager
處理稱爲xmlField
財產時使用它(如在上面的代碼片段所示):
@Entity
@Table(name="TABLE_NAME")
@NamedQueries({ /* ... */})
@Customizer(XMLDataCustomizer.class)
public class DataEntity implements Serializable {
/* ... */
private String xmlField;
/* .... */
}
的xmlField
屬性不需要@Column
anotation,因爲它映射在OU定義r DescriptorCustomizer
執行。
就是這樣。
感謝您的回答。目前,我的同事選擇將其映射爲String,並將數據庫中的列作爲CLOB類型獲取。但我仍然想知道是否有更直接的方式在Java層完成它。我會檢查你的解決方案。 – 2010-10-19 13:49:00
最後,雖然在我看來這是實現它的正確方法,但我們將繼續使用Clob解決方法。無論如何謝謝@詹姆斯。 – 2010-10-20 10:39:59
clob解決方法,你是如何得到它的工作 – 2014-04-30 16:09:16