[英]How to persist a class using hibernate which is used in many different ways?
我是新来的冬眠世界,还在学习中。 我正在尝试使用休眠方式在数据库中保留一个类。 此类的对象在其客户端类中可以具有不同的含义。 以下是我要保留的类定义:
class Entity {
int id;
String name;
}
class ClientClass {
int clientClassID;
List<Entity> employerList;
List<Entity> clientList;
}
ClientClass
映射文件如下:
<hibernate-mapping package="com.foo.bar.model">
<class name="ClientClass" table="CLIENTS">
<id name="clientClassID" column="CLIENT_ID" type="integer"
unsaved-value="0">
<generator class="native" />
</id>
<set name="clientList" table="PROJECT_CLIENTS" cascade="all">
<key column="CLIENT_ID" />
<many-to-many column="CLIENT_ID" class="Entity" />
</set>
<property name="description" type="string" length="1000" />
<set name="employerList" table="PROJECT_EMPLOYERS" cascade="all">
<key column="CLIENT_ID" />
<many-to-many column="EMPLOYER_ID" class="Entity" />
</set>
</class>
</hibernate-mapping>
我不明白如何为Entity
类编写映射? 请帮我。 如果您需要更多详细信息,请告诉我。
提前致谢 !!!
您将必须首先将Entity
映射为自己的类。
<class name="Entity" table="ENTITY">
<id name="id" column="id" type="integer"
unsaved-value="0">
<generator class="native" />
</id>
<property name="name" type="string" />
</class>
然后,您可以将其添加为其他类中的“多对多”关联。 我不太了解您在EMPLOYER_NAME
和CLIENT_ID
上的映射应如何工作。
有关更多文档,请参见: http : //docs.jboss.org/hibernate/core/3.3/reference/en/html/collections.html#collections-ofvalues
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.