老烟袋 2011-03-23 00:16
浏览 623
已采纳

Hibernate 多对多关联 中间表有多个字段如何配置

例如 :学生 与课程之间是多对多关联,中间表不仅有学生表和课程表的主键,中间表还有其他字段(成绩等),该如何配置,用
JPA如何设置,望大家指点指点|

  • 写回答

2条回答 默认 最新

  • iteye_20011 2011-03-23 10:38
    关注

    一个事例:
    LoginInfo.hbm.xml
    [code="xml"]

















    [/code]

    LoginInfo对象
    [code="java"]
    package com.ucit.ca.webApp.po;

    /**

    • CasUserModuleInfo entity. @author MyEclipse Persistence Tools */

    public class LoginInfo implements java.io.Serializable {
    // Fields
    private String lid;
    private Uinfo uinfo;
    private Module module;
    private User user;

    // Constructors
    
    /** default constructor */
    public LoginInfo() {
    }
    
    /** full constructor */
    public LoginInfo(Uinfo uinfo, Module module, User user) {
        this.uinfo = uinfo;
        this.module = module;
        this.user = user;
    }
    
    // Property accessors
    
    public Uinfo getUinfo() {
        return uinfo;
    }
    
    public String getLid() {
        return lid;
    }
    
    public void setLid(String lid) {
        this.lid = lid;
    }
    
    public void setUinfo(Uinfo uinfo) {
        this.uinfo = uinfo;
    }
    
    public Module getModule() {
        return module;
    }
    
    public void setModule(Module module) {
        this.module = module;
    }
    
    public User getUser() {
        return user;
    }
    
    public void setUser(User user) {
        this.user = user;
    }
    
    @Override
    public boolean equals(Object other) {
        if ((this == other))
            return true;
        if ((other == null))
            return false;
        if (!(other instanceof LoginInfo))
            return false;
        LoginInfo castOther = (LoginInfo) other;
    
        return ((this.getUser() == castOther.getUser()) || (this.getUser() != null
                && castOther.getUser() != null && this.getUser().equals(
                castOther.getUser())))
                && ((this.getUinfo() == castOther.getUinfo()) || (this
                        .getUinfo() != null
                        && castOther.getUinfo() != null && this.getUinfo()
                        .equals(castOther.getUinfo())))
                && ((this.getModule() == castOther.getModule()) || (this
                        .getModule() != null
                        && castOther.getModule() != null && this.getModule()
                        .equals(castOther.getModule())));
    }
    
    @Override
    public int hashCode() {
        return "com.ucit.ca.webApp.po.LoginInfo".hashCode();
    }
    

    }
    [/code]

    具体字段再加就是了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?