我该如何做这个休眠映射?

发布于 2025-01-03 19:57:22 字数 1695 浏览 3 评论 0原文

为了熟悉这个问题...

我有一组与特定表相关的表。现在,为了处理所有这些与“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满意归宿 2025-01-10 19:57:22

这仅用于读取

  <class name="One" table="table_one">
    <id name="Id" column="id">
    </id>
  </class>

  <class name="Many1" table="table_many_1">
    <id name="id">
      <column name="id_table_many_1" />
      <generator class="identity" />
    </id>
    <set cascade="all" name="Ones" table="linking_table" lazy="false" where="id_table_many_type = 'table 1'">
      <key column ="id_table_many" />
      <many-to-many column="d_table_one" class="One" />
    </set>
  </class>

writepart 取决于:table_one 到 table_many1 是 1:n 还是 n:m 关联?

this is for reading only

  <class name="One" table="table_one">
    <id name="Id" column="id">
    </id>
  </class>

  <class name="Many1" table="table_many_1">
    <id name="id">
      <column name="id_table_many_1" />
      <generator class="identity" />
    </id>
    <set cascade="all" name="Ones" table="linking_table" lazy="false" where="id_table_many_type = 'table 1'">
      <key column ="id_table_many" />
      <many-to-many column="d_table_one" class="One" />
    </set>
  </class>

the writepart depends on: is table_one to table_many1 a 1:n or n:m association?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文