I have a CourseOffering object defined in my application. It has for primary key Semester, CourseNo, and Section which are strings.
I have another object called Faculty whose primary key is fac_id which is an integer.
Now I created an association between Faculty and CourseOffering and placed that association within CourseOffering.
@ManyToMany(cascade = CascadeType.ALL) @JoinTable(name="TAUGHT_BY", joinColumns = {@JoinColumn(name = "SEMESTER", nullable = false, updatable = false), @JoinColumn(name = "COURSE_NO", nullable = false, updatable = false), @JoinColumn(name = "SECTION", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "FAC_ID", nullable = false, updatable = false) }
)
The join table is TAUGHT_BY which has a primary key as (SEMESTER_ID, COURSE_NO, SECTION and FAC_ID).
public Set<Faculty> getFaculty(){ return this.faculties; }
public void setFaculty(Set<Faculty> faculties){ this.faculties = faculties; }
I have also created a TaughtBy entity object in my application.
ISSUE -------
Now the issue is this, as I am saving my CourseOffering object. I set the CourseOffering.setFaculty and update the object.
The UPDATE QUERY FIRES and the resulting query is this: update KARYN.COURSE_OFFERING set COURSE_TITLE=?, COURSE_TOTAL=?, COURSE_TYPE=?, DATE_ENTERED=?, DATE_UPDATED=?, DISPLAY_FAC_NAME=?, ENTERED_BY=?, EVALREQD=?, MIDEVAL=?, MINI_NO=?, NO_RATERS=?, ONLINEEVAL=?, PROJCOURSE=?, RATING=?, SEM_ORDER=?, UNITS=?, UPDATED_BY=? where COURSE_NO=? and SECTION=? and SEMESTER=?
16:22:12,730 INFO [STDOUT] Hibernate: delete from TAUGHT_BY where SEMESTER=? and COURSE_NO=? and SECTION=?
16:22:12,730 INFO [STDOUT] Hibernate: insert into TAUGHT_BY (SEMESTER, COURSE_NO, SECTION, FAC_ID) values (?, ?, ?, ?)
16:22:12,746 INFO [STDOUT] Hibernate: insert into TAUGHT_BY (SEMESTER, COURSE_NO, SECTION, FAC_ID) values (?, ?, ?, ?)
16:22:12,746 INFO [STDOUT] Hibernate: insert into TAUGHT_BY (SEMESTER, COURSE_NO, SECTION, FAC_ID) values (?, ?, ?, ?)
16:22:12,746 INFO [STDOUT] Hibernate: insert into TAUGHT_BY (SEMESTER, COURSE_NO, SECTION, FAC_ID) values (?, ?, ?, ?)
while it is inserting into TAUGHTBY, maybe my relationship mapping is wrong.
I get the following error.
SQL Error: 12899, SQLState: 72000 value too large for column "KARYN"."TAUGHT_BY"."SEMESTER" (actual: 6, maximum: 3).
I verified that the SEMESTER in all the tables is of size 3. So what is happening.
P.S: THERE is 1 UPDATE QUERY AND 4 INSERT QUERIES since I am inserting 4 faculty objects into the DB. Please let me know the solution.
|