Hi,

I am trying to map our current schema to JPA.  The below SoftwareModule
entity has many-to-many mappings with other entities and those are working
correctly.  However, I cannot get it to work for a self-referencing
many-to-many mapping.

JPA is not throwing any exceptions when I try to do the following.  It just
seems to completely ignore the fact that I set the targetModules.  Most of
the info I was able to dig up online showed the exact same strategy I am
already using.

1) Persist SoftwareModuleA
2) Set the target modules for SoftwareModuleB to be SoftwareModuleA and
persist SoftwareModuleB.
3) Query for SoftwareModules :

"select x from SoftwareModule x where x.targetModules is not null"  -->
returns 0 results

"select x from SoftwareModule x where x.targetModules is null" --> returns
both of the SoftwareModule's

4) The only other interesting thing of note is that this class inherits
from a base class, but I'm not sure that is playing any part in this
problem.



@Entity(name="SoftwareModule")
@Table(name="SOFTWARE_MODULE")
@PrimaryKeyJoinColumn(name="MODULE_ID", referencedColumnName="id")
public class JPASoftwareModule extends JPAManagedElement implements
Serializable {

...........

    @ManyToMany(fetch=FetchType.EAGER)
    @JoinTable(name="sftw_mod_sftw_mod_assoc",
            joincolum...@joincolumn(name="source_module_id"),//
referencedColumnName="module_id"),
            inversejoincolum...@joincolumn(name="target_module_id"))//,
referencedColumnName="module_id"))
            private List<JPASoftwareModule> sourceModules;

    @ManyToMany(fetch=FetchType.EAGER, mappedBy="sourceModules")
    private List<JPASoftwareModule> targetModules;


Thanks

Heather Sterling
Systems Management Development
Phone:  919-254-7163 T/L: 444-7163
Cell: 919-423-3143
Email: [email protected]

Reply via email to