我有一个这样的实体:
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
对象?
使用<basic name="properties"/>
会导致错误:无法解析属性。但是,它会将BLOB列添加到数据库表中。
Properties
适用于String
个键和值,但实际上扩展了Hashtable<Object,Object>
(实现Map<Object,Object>
)。这看起来像一对多。但Object
不是一个实体,所以也不起作用。