我该如何做这个休眠映射?
为了熟悉这个问题...
我有一组与特定表相关的表。现在,为了处理所有这些与“table_one”之间的关系,我只制作了一个表,该表的主键由:
id_table_one、id_table_many、id_table_many_type组成。
第一个表示 table_one 的 id,第二个表示 table_many(其中任何一个)的 id,第三个键是一个字符串,表示表的类型。
更具体的例子:
1、1、“表1”-> 的第1行的关系
表示table_many“表1”(第1行)与table_one 3、5 ,“表1”->表示table_many“表1”(第5行)与table_one 3、5的第3行的关系
,“表2”->表示table_many“表2”(第5行)与table_one的第3行之间的关系
这在SQL中很容易做到,但问题是,如何在每个table_many中进行hibernate映射?
我将 table_one 声明如下:
<class name="tableOne" table="table_one">
<composite-id>
<key-property name="idTableOne" type="java.lang.Integer">
<column name="id_table_one" not-null="true"/>
</key-property>
<key-property name="idTableMany" type="java.lang.Integer">
<column name="id_table_many" not-null="true"/>
</key-property>
<key-property name="idTableManyType" type="string">
<column name="id_table_many_type" length="100" not-null="true"/>
</key-property>
</composite-id>
</class>
如何将其放入多个表中?
<class name="tableMany1" table="table_many_1">
<id name="idTableMany1" type="java.lang.Integer">
<column name="id_table_many_1" />
<generator class="identity" />
</id>
<set cascade="all" name="tableOneRows" sort="unsorted"
table="table_one" lazy="false">
<...>
</set>
</class>
我不知道如何填写<...>部分...有什么建议吗?
我追求的最终目标是管理每个 tableMany 中的 tableOne (读/写)...
谢谢大家!
To acquaint with the issue...
I have a group of tables related with a specific table. now for doing the relation between all of them and the "table_one" I made only a table which has as primary key composed by:
id_table_one, id_table_many, id_table_many_type.
The first one indicates the id of the table_one, the second the id of the table_many (any of them) and the third key is a string which indicates the type of the table.
An example to be more specific:
1, 1, "table 1" -> indicates the relation between the table_many "table 1" (row 1) with the row 1 of the table_one
3, 5, "table 1" -> indicates the relation between the table_many "table 1" (row 5) with the row 3 of the table_one
3, 5, "table 2" -> indicates the relation between the table_many "table 2" (row 5) with the row 3 of the table_one
This is easy to do in SQL, but the question is, how can I do the hibernate mapping in each table_many?
I declared the table_one as follows:
<class name="tableOne" table="table_one">
<composite-id>
<key-property name="idTableOne" type="java.lang.Integer">
<column name="id_table_one" not-null="true"/>
</key-property>
<key-property name="idTableMany" type="java.lang.Integer">
<column name="id_table_many" not-null="true"/>
</key-property>
<key-property name="idTableManyType" type="string">
<column name="id_table_many_type" length="100" not-null="true"/>
</key-property>
</composite-id>
</class>
How can I do the into the many tables?
<class name="tableMany1" table="table_many_1">
<id name="idTableMany1" type="java.lang.Integer">
<column name="id_table_many_1" />
<generator class="identity" />
</id>
<set cascade="all" name="tableOneRows" sort="unsorted"
table="table_one" lazy="false">
<...>
</set>
</class>
I don't know how to fill in the <...> section...any advice?
The finality I am pursuing is to manage the tableOne (read/write) from each tableMany...
thx all!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这仅用于读取
writepart 取决于:table_one 到 table_many1 是 1:n 还是 n:m 关联?
this is for reading only
the writepart depends on: is table_one to table_many1 a 1:n or n:m association?