2

我有一个这样的实体:

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 列添加到数据库表中。

PropertiesString键和值一起使用,但实际上是扩展Hashtable<Object,Object>(实现Map<Object,Object>)。这看起来像一对多。但Object它不是一个实体,所以它也不起作用。

4

0 回答 0