Hibernate - 列名为

时间:2017-06-07 07:57:33

标签: java xml hibernate

我有两张桌子:

  • 客户:ID(密钥)
  • PERSONAL_DATA:ID(密钥),CUSTOMER_ID

是否可以创建 XML 配置:

  • 一对一关系CUSTOMERS.ID - > PERSONAL_DATA.CUTOMER.ID
  • CUSTOMERS pojo类中PERSONAL_DATA类型的属性?

1 个答案:

答案 0 :(得分:1)

是的,xmls可能如下所示:

  1. CUSTOMERS xml:
  2. <hibernate-mapping>
    	<class name="QUALIFIED_NAME_OF_CUSTOMERS" table="CUSTOMERS" catalog="YOUR_DATABASE_NAME">
    		<id name="id" type="java.lang.Integer">
    			<column name="id" />
    			<generator class="identity" />
    		</id>
    		<one-to-one name="PERSONAL_DATA" class="QUALIFIED_NAME_OF_PERSONAL_DATA"
    			cascade="save-update"></one-to-one>
    	</class>
    </hibernate-mapping>

    1. PERSONAL_DATA xml:
    2. <hibernate-mapping>
          <class name="QUALIFIED_NAME_OF_PERSONAL_DATA" table="PERSONAL_DATA"
              		catalog="YOUR_DATABASE_NAME">
              <id name="customer_id" type="java.lang.Integer">
          		    <column name="customer_id" />
                  <generator class="foreign">
      				        <param name="property">CUSTOMERS</param>
      			      </generator>
          		</id>
              <one-to-one name="CUSTOMERS" class="QUALIFIED_NAME_OF_CUSTOMERS"
              			constrained="true">
              </one-to-one>
              <property name="id" type="java.lang.Integer">
                  <column name="id" />
              </property>
              		
            </class>
      </hibernate-mapping>