【问题标题】:How should the mapping done for the many to many relationship in hibernate for this?为此在hibernate中应该如何为多对多关系进行映射?
【发布时间】:2012-07-11 03:20:51
【问题描述】:

首先我想告诉我我是新来的休眠。

我已经完成了一对一映射、一对多映射等教程,但我仍然有疑问,

我有 3 个表:

Users                            Dealfollows                         Deal
=========                        ============                        ============     
userid(PK)                       dealid(FK)                          dealid(PK) 
firstname                        userid(FK)                          name
lastname                                                             description
..                                                                   ..

所以我遇到的问题是,当我在 dealfollows 表中将 dealid 和 userid 作为 PK 以及 FK 时,休眠代码生成工具不会为 dealfollows 生成 pojo 类和 hbm 文件 所以我想分别保存/更新每个实体 用户 - 单独保存/更新 交易-单独保存/更新 Dealfollows - 当用户选择一个特定的交易然后&然后我只想在这里保存/更新它

请帮助我。提前致谢。

【问题讨论】:

    标签: hibernate jakarta-ee hibernate-mapping


    【解决方案1】:

    Dealfollows 是一个简单的链接表。 hibernate 允许你不必为此声明一个实体,而是一个 manytomany 并处理 crud 本身。例如这些类就足够了

    class User
    {
        Set<Deal> deals;
    }
    
    class Deal
    {
        Set<User> users;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-29
      • 1970-01-01
      • 1970-01-01
      • 2013-07-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多