老烟袋 2011-03-22 16:16
浏览 624
已采纳

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

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

  • 写回答

2条回答 默认 最新

  • iteye_20011 2011-03-23 02: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部