我用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
如图所示:
其中父模块的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