如何使用XML实体映射(orm.XML)持久化java.util.Properties
我有这样一个实体:如何使用XML实体映射(orm.XML)持久化java.util.Properties,java,hibernate,orm,Java,Hibernate,Orm,我有这样一个实体: public class MyEntity implements Serializable { private static final long serialVersionUID = 1L; // some fields such as Long, String etc. private java.util.Properties properties; // getters, setters, equals, hashCode, toString ..
public class MyEntity implements Serializable {
private static final long serialVersionUID = 1L;
// some fields such as Long, String etc.
private java.util.Properties properties;
// getters, setters, equals, hashCode, toString ...
}
和XML实体映射
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd">
<persistence-unit-metadata>
<persistence-unit-defaults>
<access>FIELD</access>
</persistence-unit-defaults>
</persistence-unit-metadata>
<entity class="com.package.of.my.MyEntity">
<table name="my_entity">
<unique-constraint name="uniquefield">
<column-name>uniquefield</column-name>
</unique-constraint>
</table>
<!-- some named queries -->
<attributes>
<id name="id"><generated-value/></id>
<!-- some <basic name="..."> columns -->
<!-- What to put here for mapping the properties field? -->
<!-- other mappings (one-to-one, one-to-many, many-to-many) -->
</attributes>
</entity>
<!-- other entity mappings -->
</entity-mappings>
领域
唯一字段
如何理想地映射java.util.Properties
对象
使用
会导致错误:无法解析属性。但是,它会向数据库表中添加BLOB列
Properties
使用String
键和值,但实际上扩展了Hashtable
(它实现了Map
)。这看起来像是一对多。但是对象
不是一个实体,因此也不起作用