首页 新闻 会员 周边 捐助

Hibernate Self Join Annotations One To Many IllegalArgumentException?

0
悬赏园豆:10 [待解决问题]

我用Hibernate annotation从one方获取many方总是报 IllegalArgumentException异常? 
我的sys_Module是一个自身关联的实体 
表结构如下: 

其中父模块的M_ParentID字段值为0,子模块通过M_ParentID字段关联父模块的ModuleID值,ModuleID自增型 
字段M_ApplicationID和字段M_PageCode为联合主键 
sys_Module类code如下: 

 

  1 @Entity
  2 @Table(name="sys_Module")
  3 public class SysModule  implements java.io.Serializable {
  4     
  5     private static final long serialVersionUID = 1L;
  6     
  7     
  8 
  9      /**
 10       *            @hibernate.id
 11  *             generator-class="assigned"
 12  *         
 13      */
 14      private SysModulePK comp_id;
 15      /**
 16       *            @hibernate.property
 17  *             column="ModuleID"
 18  *             length="10"
 19  *             not-null="true"
 20  *         
 21      */
 22      private Long moduleId;
 23      /**
 24       *            @hibernate.property
 25  *             column="M_ParentID"
 26  *             length="10"
 27  *             not-null="true"
 28  *         
 29      */
 30      //private int mparentId;
 31      /**
 32       *            @hibernate.property
 33  *             column="M_CName"
 34  *             length="50"
 35  *         
 36      */
 37      private String mcname;
 38      /**
 39       *            @hibernate.property
 40  *             column="M_Directory"
 41  *             length="255"
 42  *         
 43      */
 44      private String mdirectory;
 45      /**
 46       *            @hibernate.property
 47  *             column="M_OrderLevel"
 48  *             length="4"
 49  *         
 50      */
 51      private String morderLevel;
 52      /**
 53       *            @hibernate.property
 54  *             column="M_IsSystem"
 55  *             length="3"
 56  *         
 57      */
 58      private Byte misSystem;
 59      /**
 60       *            @hibernate.property
 61  *             column="M_Close"
 62  *             length="3"
 63  *         
 64      */
 65      private Byte mclose;
 66      /**
 67       *            @hibernate.property
 68  *             column="M_Icon"
 69  *             length="255"
 70  *         
 71      */
 72      private String micon;
 73      
 74      
 75      private SysModule parentSysModule;
 76      
 77      //private SysApplication sysApplication;
 78      
 79      private List<SysModule> subsysModules;
 80 
 81     
 82    
 83     /**       
 84      *      *            @hibernate.id
 85      *             generator-class="assigned"
 86      *         
 87      */
 88      //@AttributeOverrides({@AttributeOverride(name="mapplicationId", column=@Column(name="M_ApplicationID")),@AttributeOverride(name="mpageCode", column=@Column(name="M_PageCode"))})
 89 //     @EmbeddedId
 90 //     @AttributeOverrides({
 91 //         @AttributeOverride(name="mapplicationId", column=@Column(name="M_ApplicationID",nullable=false)),
 92 //         @AttributeOverride(name="mpageCode", column=@Column(name="M_PageCode",nullable=false))
 93 //         })
 94      
 95      //@AttributeOverride(name="mapplicationId", column=@Column(name="M_ApplicationID",nullable=false,insertable=true, updatable=true)),
 96      //@AttributeOverride(name="mpageCode", column=@Column(name="M_PageCode",nullable=false,insertable=true, updatable=true))
 97      
 98      
 99     @EmbeddedId    
100     public SysModulePK getComp_id() {
101         return this.comp_id;
102     }
103     
104     public void setComp_id(SysModulePK comp_id) {
105         this.comp_id = comp_id;
106     }
107      
108     
109      
110      
111     /**       
112      *      *            @hibernate.property
113      *             column="ModuleID"
114      *             length="10"
115      *             not-null="true"
116      *         
117      */
118     
119       @GeneratedValue(strategy = IDENTITY)
120     @Column(name="ModuleID",unique=true, nullable=false)
121     public Long getModuleId() {
122         return this.moduleId;
123     }
124     
125     public void setModuleId(Long moduleId) {
126         this.moduleId = moduleId;
127     }
128     /**       
129      *      *            @hibernate.property
130      *             column="M_ParentID"
131      *             length="10"
132      *             not-null="true"
133      *         
134      */
135 //    @Column(name="M_ParentID",nullable=false)
136 //    public int getMparentId() {
137 //        return this.mparentId;
138 //    }
139 //    
140 //    public void setMparentId(int mparentId) {
141 //        this.mparentId = mparentId;
142 //    }
143     /**       
144      *      *            @hibernate.property
145      *             column="M_CName"
146      *             length="50"
147      *         
148      */
149     @Column(name="M_CName",length=50)
150     public String getMcname() {
151         return this.mcname;
152     }
153     
154     public void setMcname(String mcname) {
155         this.mcname = mcname;
156     }
157     /**       
158      *      *            @hibernate.property
159      *             column="M_Directory"
160      *             length="255"
161      *         
162      */
163     @Column(name="M_Directory",length=255)
164     public String getMdirectory() {
165         return this.mdirectory;
166     }
167     
168     public void setMdirectory(String mdirectory) {
169         this.mdirectory = mdirectory;
170     }
171     /**       
172      *      *            @hibernate.property
173      *             column="M_OrderLevel"
174      *             length="4"
175      *         
176      */
177     @Column(name="M_OrderLevel",length=4)
178     public String getMorderLevel() {
179         return this.morderLevel;
180     }
181     
182     public void setMorderLevel(String morderLevel) {
183         this.morderLevel = morderLevel;
184     }
185     /**       
186      *      *            @hibernate.property
187      *             column="M_IsSystem"
188      *             length="3"
189      *         
190      */
191     @Column(name="M_IsSystem")
192     public Byte getMisSystem() {
193         return this.misSystem;
194     }
195     
196     public void setMisSystem(Byte misSystem) {
197         this.misSystem = misSystem;
198     }
199     /**       
200      *      *            @hibernate.property
201      *             column="M_Close"
202      *             length="3"
203      *         
204      */
205     @Column(name="M_Close")
206     public Byte getMclose() {
207         return this.mclose;
208     }
209     
210     public void setMclose(Byte mclose) {
211         this.mclose = mclose;
212     }
213     /**       
214      *      *            @hibernate.property
215      *             column="M_Icon"
216      *             length="255"
217      *         
218      */
219     @Column(name="M_Icon",length=255)
220     public String getMicon() {
221         return this.micon;
222     }
223     
224     public void setMicon(String micon) {
225         this.micon = micon;
226     }
227 //    //@JoinColumns({@JoinColumn(name="M_ParentID",referencedColumnName="ModuleID")})
228     //@ManyToOne(cascade={CascadeType.ALL})
229     //@ManyToOne(cascade={CascadeType.ALL},fetch = FetchType.LAZY)
230     
231     @ManyToOne(cascade={CascadeType.ALL},fetch = FetchType.LAZY)
232     @JoinColumn(name="M_ParentID",referencedColumnName="ModuleID",insertable=false,updatable=false)
233     public SysModule getParentSysModule() {
234         return parentSysModule;
235     }
236 
237     public void setParentSysModule(SysModule parentSysModule) {
238         this.parentSysModule = parentSysModule;
239     }
240     //@OneToMany(mappedBy="parentSysModule")
241     //@JoinColumn(name="M_ParentID",referencedColumnName="ModuleID",insertable=false,updatable=false)
242     
243     @OneToMany(mappedBy="parentSysModule",fetch=FetchType.LAZY , cascade={CascadeType.ALL})
244     @OrderBy("morderLevel DESC")
245     public List<SysModule> getSubsysModules() {
246         return subsysModules;
247     }
248 
249     public void setSubsysModules(List<SysModule> subsysModules) {
250         this.subsysModules = subsysModules;
251     }
252 //    @ManyToOne  
253 //    @JoinColumn(name="M_ApplicationID",insertable=false,updatable=false)
254 //    public SysApplication getSysApplication() {
255 //        return sysApplication;
256 //    }
257 //
258 //    public void setSysApplication(SysApplication sysApplication) {
259 //        this.sysApplication = sysApplication;
260 //    }
261  // plumbing
262     @Override
263     public boolean equals(Object obj) {
264       return reflectionEquals(this, obj);
265     }
266     
267     @Override
268     public int hashCode() {
269       return reflectionHashCode(this);
270     }
271     
272     @Override
273     public String toString() {
274       return reflectionToString(this);
275     }
276     
277 
278     
279     
280 }

其中是复合主键SysModulePK: 

public class SysModulePK  implements java.io.Serializable {
    
    private static final long serialVersionUID = 1L;

     /**
      *                @hibernate.property
 *                 column="M_ApplicationID"
 *                 length="10"
 *             
     */
    
     private Long mapplicationId;
     /**
      *                @hibernate.property
 *                 column="M_PageCode"
 *                 length="6"
 *             
     */
     private String mpageCode;

   
   
    /**       
     *      *                @hibernate.property
     *                 column="M_ApplicationID"
     *                 length="10"
     *             
     */
     //@Column(name="M_ApplicationID",nullable=false,insertable = false, updatable = false)
     @Column(name="M_ApplicationID",nullable=false)
    public Long getMapplicationId() {
        return this.mapplicationId;
    }
    
    public void setMapplicationId(Long mapplicationId) {
        this.mapplicationId = mapplicationId;
    }
    /**       
     *      *                @hibernate.property
     *                 column="M_PageCode"
     *                 length="6"
     *             
     */
    //@Column(name="M_PageCode",nullable=false,insertable = false, updatable = false)
    @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);
      }
}

当我load一个sysModule实体后(可以获取sysModule,不报下面的异常),再获取sysModule.getSubsysModules()时,总是报异常: 
IllegalArgumentException occurred calling getter of com.hedgehog.domain.SysModulePK.mapplicationId

请问我的代码是哪里有问题? 
我调试这个问题 三天了

 

 

刺猬的温驯的主页 刺猬的温驯 | 初学一级 | 园豆:187
提问于:2012-05-04 06:35
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册