老烟袋 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 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建