2011-12-01 46 views
0

我想映射集合(类型映射)。休眠IndexColumn与地图

Below are the tables 
Product: 
    PID - primary key 
    NAME 

ProductProperties: 
    ID - primary key auto_increment 
    PID - FK references Product(ID)(INDEXED) 
    KEY - (INDEXED) 
    VALUE 

及以下用于映射

<?xml version="1.0"?> 
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> 
<hibernate-mapping> 
    <class name="com.test.Product" table="product" catalog="cart"> 
     <id name="pid" type="long"> 
      <column name="pid" /> 
      <generator class="assigned" /> 
     </id> 
     <property name="name" type="string"> 
      <column name="name" length="100" not-null="true" /> 
     </property> 
     <map name="properties" table="properties" cascade="all"> 
      <key column="pid" not-null="true"/> 
      <map-key column="key" type="string"/> 
      <element column="value" type="string"/> 
     </map> 
    </class> 
</hibernate-mapping> 

在许多例子中的HBM文件,我看不是。

我对此有几个问题。

  1. 为什么使用IndexColumn而不是map-key?
  2. 哪个更好? IndexColumn或map-key
  3. 我在哪里可以找到详细的文档来了解IndexColumn和map-key?

请提前帮助并提前致谢。

回答

0

你的意思是问

<map ...> 
    <map-key .../> 
</map> 

<map ...> 
    <index .../> 
</map> 

之间的差异在运行时,它们将被解释如出一辙。我猜< index>被保留为与hibernate 2.0向后兼容,他们在< map>和< list>中使用了相同的元素。在休眠3.0中,首选< map-key>。

对于文档,我只使用参考,但它并没有给你太多的细节。除非你会阅读DTD:http://www.jboss.org/dtd/hibernate/hibernate-mapping-3.0.dtd

+0

谢谢你这么灰 – user1075205