使用 Hibernate 多对多连接表中再添加一列

发布于 2024-09-12 18:47:14 字数 321 浏览 2 评论 0原文

我如何映射这样的结构 数据库模型 http://imagepost.ru/images/186/oefb4v6.png 其中

class A{
    Map<SomeEnum, B> foo;
}

foo 中的 key 是 a_ has _brole 的表示?

谢谢!

How i can map structure like this
db model http://imagepost.ru/images/186/oefb4v6.png
into

class A{
    Map<SomeEnum, B> foo;
}

where key in foo is representation of role in a_ has _b ?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

完美的未来在梦里 2024-09-19 18:47:14

如果您想要表列中的枚举常量的名称:

<hibernate-mapping ...>
...
  <typedef name="role" class="org.hibernate.type.EnumType">
    <param name="enumClass">SomeEnum</param>
    <param name="type">12</param>
  </typedef>
...
  <class name="A" table="a">
...
    <map name="foo" table="a_has_b">
      <key column="a_id"/>
      <map-key type="role" length="20" column="role"/>
      <many-to-many class="b" column="b_id"/>
    </set>
...
  </class>
...
  <class name="B">
...
  </class>
...
</hibernate-mapping>

If you want the name of the enum constants in your table column:

<hibernate-mapping ...>
...
  <typedef name="role" class="org.hibernate.type.EnumType">
    <param name="enumClass">SomeEnum</param>
    <param name="type">12</param>
  </typedef>
...
  <class name="A" table="a">
...
    <map name="foo" table="a_has_b">
      <key column="a_id"/>
      <map-key type="role" length="20" column="role"/>
      <many-to-many class="b" column="b_id"/>
    </set>
...
  </class>
...
  <class name="B">
...
  </class>
...
</hibernate-mapping>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文