老烟袋 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 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度