I stumbled accross a test scenario and did not think it was working right. 
Before posting a bug, I wanted to check if this scenario was already addressed 
(either in this forum or other forums).

I have three tables:

STUDENT (SID INT, SFSTNM VCHAR10, SLSTNM VCHAR10)
TEAM (TID INT, NAME VCHAR10)
COLLEGE( STUDID INT - REFERENCING SID STUDENT table, TEAMID INT - REFERENCING 
TID of TEAM table)

STUDENT entity defines a owning relation of ManyToMany with TEAM as follows:

    @ManyToMany ()
    @JoinTable(name="COLLEGE", [EMAIL PROTECTED](name="STUDID", 
referencedColumnName="SID"), [EMAIL PROTECTED](name="TEAMID", 
referencedColumnName="TID"))
    public List<Team> getTeamCollection() {
        return teamCollection;
    }

TEAM entity defines the inverse relation as below:

    @ManyToMany(mappedBy="teamCollection")
    public List<Student> getStudentList() {
        return studentList;
    }

Data in the tables is as follows:
Student
SID         SFSTNM     SLSTNM
----------- ---------- ----------
          1 ONE        LAST
          2 TWO        LAST

Team
TID         TNAME
----------- ----------
        100 TEAM 100
        200 TEAM 200

College
STUDID      TEAMID
----------- -----------
          2         200
          1         100
          2         100
          1         200

Scenario 1:
Using EntityManager, I find the Student entity with PK value "1". Access the 
team list and remove the entry in the list with TID "100". Now when I commit 
this transaction, the entry from intermediate table (COLLEGE) with STUDID "1" 
and TEAMID "100" is removed.

Scenario 2:
Using EntityManager, I find the Team entity with PK value "200". Access the 
student list and remove the entry in the list with SID "1". On comitting the 
transaction, no changes are noticed in the COLLEGE table.

Conclusion:
With this testing, I am able to conclude that, using owner side of ManyToMany 
relation, we can remove entries from JoinTable (with or without any cascade 
option - Yes, I tried with no cascade option, refresh cascade option), where as 
from the inverse side of ManyToMany, we are unable to remove.

I have looked up the JSR 220 and did not find any specific mention on this 
scenario. This seems like a bug in the implementation. Please let me know if 
this really is a bug, so I can submit a bug report.

Regards
Jitendra.



      

Reply via email to