当前位置: 代码迷 >> Java Web开发 >> hibernate annotation 主键生成策略有关问题
  详细解决方案

hibernate annotation 主键生成策略有关问题

热度:676   发布时间:2016-04-17 01:21:19.0
hibernate annotation 主键生成策略问题
hibernate annotation 主键生成策略问题:
  我有一个表,主键是id varchar(32) <pk,fk>
  我应该怎样设置annotation,让id既是uuid的生成策略,又是外键了.(与外表是多对一关联).
 最好有例子啊!!谢谢啊

------解决方案--------------------
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- 
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.mmc.bean.Brand" table="brand" schema="dbo" catalog="computerdb" lazy="false">
<id name="bid" type="java.lang.String">
<column name="bid" length="32" />
<generator class="uuid.hex" />
</id>
<property name="bname" type="java.lang.String">
<column name="bname" length="30" />
</property>
<set name="montherboards" inverse="true">
<key>
<column name="brand_id" length="32" />
</key>
<one-to-many class="com.mmc.bean.Montherboard" />
</set>
<set name="models" inverse="true">
<key>
<column name="bid" length="32" />
</key>
<one-to-many class="com.mmc.bean.Model" />
</set>
<set name="monitors" inverse="true">
<key>
<column name="brand_id" length="32" />
</key>
<one-to-many class="com.mmc.bean.Monitor" />
</set>
<set name="cpus" inverse="true">
<key>
<column name="brand_id" length="32" />
</key>
<one-to-many class="com.mmc.bean.Cpu" />
</set>
<set name="memories" inverse="true">
<key>
<column name="brand_id" length="32" />
</key>
<one-to-many class="com.mmc.bean.Memory" />
</set>
<set name="keyboards" inverse="true">
<key>
<column name="brand_id" length="32" />
</key>
<one-to-many class="com.mmc.bean.Keyboard" />
</set>
<set name="videos" inverse="true">
<key>
<column name="brand_id" length="32" />
</key>
<one-to-many class="com.mmc.bean.Video" />
</set>
<set name="mouses" inverse="true">
<key>
<column name="brand_id" length="32" />
</key>
<one-to-many class="com.mmc.bean.Mouse" />
</set>
<set name="harddisks" inverse="true">
<key>
<column name="brand_id" length="32" />
</key>
<one-to-many class="com.mmc.bean.Harddisk" />
  相关解决方案