-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Hibernate Self Join Annotations OneToMany IllegalArgumentE
PostPosted: Fri May 04, 2012 7:48 pm 
Newbie

Joined: Fri May 04, 2012 7:37 pm
Posts: 2
我用Hibernate annotation从one方获取many方总是报 IllegalArgumentException异常?
我的sys_Module是一个自身关联的实体
表结构如下:
CREATE TABLE [dbo].[sys_Module] (
[ModuleID] [int] IDENTITY (1, 1) NOT NULL ,
[M_ApplicationID] [int] NOT NULL ,
[M_ParentID] [int] NOT NULL ,
[M_PageCode] [varchar] (6) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[M_CName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
[M_Directory] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
[M_OrderLevel] [varchar] (4) COLLATE Chinese_PRC_CI_AS NULL ,
[M_IsSystem] [tinyint] NULL ,
[M_Close] [tinyint] NULL ,
[M_Icon] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
如图所示:
Image
其中父模块的M_ParentID字段值为0(M_ParentID字段默认值),子模块通过M_ParentID字段关联父模块的ModuleID值,ModuleID自增型
字段M_ApplicationID和字段M_PageCode为联合主键
sys_Module类code如下:
Code:
package com.hedgehog.domain;

import static javax.persistence.GenerationType.IDENTITY;
import static org.apache.commons.lang.builder.EqualsBuilder.reflectionEquals;
import static org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode;
import static org.apache.commons.lang.builder.ToStringBuilder.reflectionToString;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.GeneratedValue;

@Entity
@Table(name="sys_Module")
public class SysModule  implements java.io.Serializable {
   
   private static final long serialVersionUID = 1L;   

    private long moduleId;
   
    private SysModulePK comp_id;
     
     private long mparentId;

     private String mcname;
 
     private String mdirectory;

     private String morderLevel;

     private Byte misSystem;

     private Byte mclose;

     private String micon;     
     
     //private SysModule parentSysModule;     
     
     private List<SysModule> subsysModules;     
       
     @GeneratedValue(strategy = IDENTITY)
     @Column(name="ModuleID",unique=true, nullable=false)
     public long getModuleId() {
         return this.moduleId;
     }
     
     public void setModuleId(long moduleId) {
         this.moduleId = moduleId;
     }
     
    @EmbeddedId   
    public SysModulePK getComp_id() {
        return this.comp_id;
    }
   
    public void setComp_id(SysModulePK comp_id) {
        this.comp_id = comp_id;
    }
       
    @Column(name="M_ParentID",nullable=false)
    public long getMparentId() {
        return this.mparentId;
    }
   
    public void setMparentId(long mparentId) {
        this.mparentId = mparentId;
    }
   
    @Column(name="M_CName",length=50)
    public String getMcname() {
        return this.mcname;
    }
   
    public void setMcname(String mcname) {
        this.mcname = mcname;
    }
   
    @Column(name="M_Directory",length=255)
    public String getMdirectory() {
        return this.mdirectory;
    }
   
    public void setMdirectory(String mdirectory) {
        this.mdirectory = mdirectory;
    }
   
    @Column(name="M_OrderLevel",length=4)
    public String getMorderLevel() {
        return this.morderLevel;
    }
   
    public void setMorderLevel(String morderLevel) {
        this.morderLevel = morderLevel;
    }
   
    @Column(name="M_IsSystem")
    public Byte getMisSystem() {
        return this.misSystem;
    }
   
    public void setMisSystem(Byte misSystem) {
        this.misSystem = misSystem;
    }
   
    @Column(name="M_Close")
    public Byte getMclose() {
        return this.mclose;
    }
   
    public void setMclose(Byte mclose) {
        this.mclose = mclose;
    }
   
    @Column(name="M_Icon",length=255)
    public String getMicon() {
        return this.micon;
    }
   
    public void setMicon(String micon) {
        this.micon = micon;
    }
   
   
    @OneToMany(fetch=FetchType.LAZY , cascade={CascadeType.ALL})
    @JoinColumn(name="M_ParentID",referencedColumnName="ModuleID",insertable=false,updatable=false)
    @OrderBy("morderLevel DESC")
    public List<SysModule> getSubsysModules() {
      return subsysModules;
   }

   public void setSubsysModules(List<SysModule> subsysModules) {
      this.subsysModules = subsysModules;
   }

// plumbing
    @Override
    public boolean equals(Object obj) {
      return reflectionEquals(this, obj);
    }
   
    @Override
    public int hashCode() {
      return reflectionHashCode(this);
    }
   
    @Override
    public String toString() {
      return reflectionToString(this);
    }   
}

其中SysModulePK是复合主键:
Code:
package com.hedgehog.domain;

import static org.apache.commons.lang.builder.EqualsBuilder.reflectionEquals;
import static org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode;
import static org.apache.commons.lang.builder.ToStringBuilder.reflectionToString;

public class SysModulePK  implements java.io.Serializable {
   
   private static final long serialVersionUID = 1L;     
   
     private long mapplicationId;
   
     private String mpageCode;
   
    @Column(name="M_ApplicationID",nullable=false)
    public long getMapplicationId() {
        return this.mapplicationId;
    }
   
    public void setMapplicationId(long mapplicationId) {
        this.mapplicationId = mapplicationId;
    }
   
    @Column(name="M_PageCode",nullable=false)
    public String getMpageCode() {
        return this.mpageCode;
    }
   
    public void setMpageCode(String mpageCode) {
        this.mpageCode = mpageCode;
    }
     // plumbing
     @Override
     public boolean equals(Object obj) {
       return reflectionEquals(this, obj);
     }
    
     @Override
     public int hashCode() {
       return reflectionHashCode(this);
     }
    
     @Override
     public String toString() {
       return reflectionToString(this);
     }
}

当我通过Hibernate session的load方法获取sysModule实体后(可以获取sysModule并能够print出各property的值,不报下面的异常),再获取sysModule.getSubsysModules()时,总是报异常:
org.hibernate.property.BasicPropertyAccessor
IllegalArgumentException in class:com.hedgehog.domain.SysModulePK,getter method of property :mapplicationId

请问我的代码是哪里有问题?
我调试这个问题 三天了 哪位可以帮我?
my hibernate version is hibernate 3.5.6-Final


Top
 Profile  
 
 Post subject: Re: Hibernate Self Join Annotations OneToMany IllegalArgumentE
PostPosted: Fri May 04, 2012 9:48 pm 
Newbie

Joined: Thu May 03, 2012 10:20 pm
Posts: 4
You can go to website inquires about it.


Top
 Profile  
 
 Post subject: Re: Hibernate Self Join Annotations OneToMany IllegalArgumentE
PostPosted: Sat May 05, 2012 4:24 am 
Newbie

Joined: Fri May 04, 2012 7:37 pm
Posts: 2
enilag wrote:
You can go to website inquires about it.

我查了一些资料,还是没有找到解决方法

看抛出的异常是 不合法的参数异常,可能是从数据表查出来的数据与实体类的属性不匹配


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.