我这边有两张表,一张日程表(Calendar),一张打球人信息表(Play)
日程表的持久化类有这样的集合:
1 private Set<Play> plays = new HashSet<Play>(0); 2 public Set<Play> getPlays() { 3 return plays; 4 } 5 public void setPlays(Set<Play> plays) { 6 this.plays = plays; 7 }
打球人信息表里面有集合:
1 public Set<Calendar> getCalendars() { 2 return calendars; 3 } 4 public void setCalendars(Set<Calendar> calendars) { 5 this.calendars = calendars; 6 }
配置文件信息为:
Calendar.hbm.xml:
1 <set name="plays" inverse="true" table="cpguanxi" cascade="save-update"> 2 <key column="cid"></key> 3 <many-to-many column="pid" class="bean.Play"></many-to-many> 4 </set>
Play.hbm.xml:
1 <set name="calendars" inverse="true" cascade="save-update" table="cpguanxi"> 2 <key column="pid"></key> 3 <many-to-many column="cid" class="bean.Calendar"></many-to-many> 4 </set>
为什么级联保存的时候,我只能保存日程信息,打球人的信息保存不了呢?是不是配置哪边出问题了,请大神指点。
这是保存时的内容
1 Calendar richeng = new Calendar(); 2 String date = "2015-04-05"; 3 int pNum = 2; 4 String playTime = "7:00"; 5 int playId = 14; 6 String fieldName = "Founders Club at Pawleys Island"; 7 richeng.setPlayTime(date); 8 richeng.setPeopleNum(pNum); 9 richeng.setOpenBall(playTime); 10 richeng.setPlayId(playId); 11 richeng.setName(fieldName); 12 13 //添加此日程的打球人信息 14 Play play = new Play(); 15 play.setName(name); 16 play.setOpid(playId); 17 play.setTel(tel); 18 richeng.getPlays().add(play); 19 play.getCalendars().add(richeng); 20 //调用services里面的方法保存日程信息 21 userService.saveRiCheng(richeng);
还未解决,为什么没有人回答我呢?