Hallo,
ich verstehe nicht warum die 1:n Beziehung nicht gemappt wird. Hier mal das Mapping für meine beiden Tabellen:
school
Code:
<hibernate-mapping package="com.businessobjects">
<class name="SchoolBO" table="HR_SCHOOL" lazy="true">
<id name="pk" column="ID">
<generator class="increment" />
</id>
<property
name="startSchool"
column="START_SCHOOL"
not-null="true"/>
<property
name="endSchool"
column="END_SCHOOL"
not-null="true"/>
<property
name="day"
column="DAY"
type="string"
not-null="true"
length="11"/>
<property
name="startTime"
column="START_TIME"
not-null="true"/>
<property
name="endTime"
column="END_TIME"
not-null="true"/>
<many-to-one
name="idPersonalDataSheet"
column="ID_PERSONAL_DATA_SHEET"
class="com.businessobjects.PersonalDataSheetBO"/>
</class>
</hibernate-mapping>
PersonalDataSheetCode:
<hibernate-mapping package="com.businessobjects">
<class name="PersonalDataSheetBO" table="HR_PERSONAL_DATA_SHEET">
<id name="pk" column="ID_PERSONAL_DATA_SHEET" unsaved-value="null">
<generator class="increment"/>
</id>
<property
name="createDate"
column="CREATE_DATE"
type="timestamp" />
<property
name="givenName"
column="FIRST_NAME"
type="string"
not-null="true"
length="50"/>
<property
name="surname"
column="LAST_NAME"
type="string"
not-null="true"
length="50"/>
<property
name="birthday"
column="BIRTHDAY"
not-null="true"/>
<property
name="image"
column="IMAGE"
not-null="true" />
<property
name="fname"
column="IMAGE_FILE_NAME"
type="string"
not-null="true"
length="255"/>
<property
name="mime"
column="MIME_TYPE"
type="string"
not-null="true"
length="50"/>
<bag name="school"
lazy="false"
table="HR_SCHOOL"
cascade="all-delete-orphan"
inverse="true" >
<key column="ID_PERSONAL_DATA_SHEET" />
<one-to-many class="com.businessobjects.SchoolBO" />
</bag>
</class>
</hibernate-mapping>
Und hier noch der Aufruf in meiner Manager Klasse:
Code:
public int createPersonalDataSheetBO(AdminPersonalDataSheetForm apf) throws FileNotFoundException, IOException, DatastoreException {
HibernateUtil.beginTransaction();
Session s = HibernateUtil.getSession();
PersonalDataSheetBO pb = new PersonalDataSheetBO();
//create a timestamp
Calendar c = Calendar.getInstance();
long l = c.getTimeInMillis();
Timestamp ts = new Timestamp(l);
pb.setCreateDate(ts);
pb.setGivenName(apf.getGivenName());
pb.setSurname(apf.getSurname());
pb.setBirthday(apf.getBirthday());
pb.setImage(apf.getFile().getFileData());
pb.setFname(apf.getFname());
pb.setMime(apf.getMime());
//s.save(pb);
SchoolBO sb = null;
List school = new ArrayList();
String [] weekArray = apf.getStrArray();
for(int i=0; i < apf.getStrArray().length; i++){
sb = new SchoolBO();
//sb.setIdPersonalDataSheet(pb.getPk());
sb.setDay(weekArray[i]);
sb.setStartSchool(apf.getSchoolStart());
sb.setEndSchool(apf.getSchoolEnd());
if(weekArray[i].equals("Montag")){
sb.setStartTime(apf.getStartMonday());
sb.setEndTime(apf.getEndMonday());
}
if(weekArray[i].equals("Dienstag")){
sb.setStartTime(apf.getStartTuesday());
sb.setEndTime(apf.getEndTuesday());
}
if(weekArray[i].equals("Mittwoch")){
sb.setStartTime(apf.getStartWednesday());
sb.setEndTime(apf.getEndWednesday());
}
if(weekArray[i].equals("Donnerstag")){
sb.setStartTime(apf.getStartThursday());
sb.setEndTime(apf.getEndThursday());
}
if(weekArray[i].equals("Freitag")){
sb.setStartTime(apf.getStartFrieday());
sb.setEndTime(apf.getEndFrieday());
}
school.add(sb);
pb.setSchool(school);
}
pb.getSchool().retainAll(school);
pb.getSchool().addAll(school);
s.save(pb);
//s.flush();
HibernateUtil.commitTransaction();
return pb.getPk();
}
Hoffe mir kann jemand helfen, in der Hibernate Doku habe ich leider auch nicht den Grund gefunden.