users@glassfish.java.net

Problem with _at_JoinTable

From: <glassfish_at_javadesktop.org>
Date: Sun, 04 Jan 2009 22:03:56 PST

Hi there,

I'm using NB 6.5 and Glassfish V2. All Entities were generated from my DB and the SessionBeans were generated from the Entities using the respective wizards.

I'm experiencing a problem with updating tables which consist of primary keys of two other tables. The generated Entities seem to have the right annotations, for example:

[code]
...
@ManyToMany(mappedBy = "phoneNumberCollection")
private Collection<IndyAxisCameras> cameraUserIdCollection;
@ManyToMany(mappedBy = "phoneNumberCollection")
private Collection<IndyAxisVideoServers> serverUserIdCollection;
...

...
@JoinTable(name = "ASSIGNED_INDY_AXIS_CAMERAS",
        joinColumns = {_at_JoinColumn(name = "DEVICE_USER_ID",
                       referencedColumnName = "DEVICE_USER_ID")},
        inverseJoinColumns = {_at_JoinColumn(name = "PHONE_NUMBER",
                              referencedColumnName = "PHONE_NUMBER")})
@ManyToMany
private Collection<IndyMobilePhones> phoneNumberCollection;
...

...
@JoinTable(name = "ASSIGNED_INDY_AXIS_VIDEO_SERVERS",
        joinColumns = {_at_JoinColumn(name = "DEVICE_USER_ID",
                       referencedColumnName = "DEVICE_USER_ID")},
        inverseJoinColumns = {_at_JoinColumn(name = "PHONE_NUMBER",
                              referencedColumnName = "PHONE_NUMBER")})
@ManyToMany
private Collection<IndyMobilePhones> phoneNumberCollection;
...
[/code]

I'm trying to update the tables as follow:

[code]
public void assignIndyAxisDevices(String selectedPhoneNumber,
                                                         List<String> cameraUserIds,
                                                         String[] selectedDevices)
                                                                                        throws Exception {
        ArrayList<IndyAxisCameras> selectedCameras =
                                               new ArrayList<IndyAxisCameras>();
        ArrayList<IndyAxisVideoServers> selectedVideoServers =
                                          new ArrayList<IndyAxisVideoServers>();
        int length = selectedDevices.length;
        for ( int i = 0; i < length; i++ ) {
            if ( isCamera(selectedDevices[i], cameraUserIds) ) {
                selectedCameras.add(indyAxisCamerasFacade.
                                                        find(selectedDevices[i]));
               
            }
            else {
                selectedVideoServers.add(indyAxisVideoServersFacade.
                                                        find(selectedDevices[i]));
               
            }
        }
        // get the mobile phone object
        IndyMobilePhones phone = getPhoneFromPhoneNumber(selectedPhoneNumber);
        // assign cameras
        if ( !selectedCameras.isEmpty() ) {
            phone.setCameraUserIdCollection(selectedCameras);
        }
        // assign video servers
        if ( !selectedVideoServers.isEmpty() ) {
            phone.setServerUserIdCollection(selectedVideoServers);
        }
        // merge
        edit(phone);
    }
[/code]

The problem is that no data gets updated in the table, no exception is thrown and all data which should go in the table exist already in the other tables.

What do I miss here?

Thanks in advance.
Stephan
[Message sent by forum member 'bardubitzki' (bardubitzki)]

http://forums.java.net/jive/thread.jspa?messageID=324024