Hi all
I've a simple entity class, representing an organization unit. This is the class
Code:
public class Wforgunit implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected WforgunitPK wforgunitPK;
    @Basic(optional = false)
    @Column(name = "livello", nullable = false)
    private short livello;
    @Column(name = "descr", length = 100)
    private String descr;
    @Basic(optional = false)
    @Column(name = "seq", nullable = false)
    private int seq;
    @Column(name = "iduparent", length = 12)
    private String iduparent;
This is the embedded primary key of the table
Code:
public class WforgunitPK implements Serializable {
    @Basic(optional = false)
    @Column(name = "codit", nullable = false, length = 2)
    private String codit;
    @Basic(optional = false)
    @Column(name = "idorg", nullable = false, length = 8)
    private String idorg;
    @Basic(optional = false)
    @Column(name = "idunit", nullable = false, length = 12)
    private String idunit;
I need a self relation to retrieve all the children of the current organization unit (the field iduparent contains the parent idunit) so I've written a self relationship like:
Code:
@OneToMany(fetch=FetchType.EAGER, targetEntity=Wforgunit.class)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumns({
        @JoinColumn(table="wforgunit", name = "codit", referencedColumnName = "codit", updatable = false, insertable = false),
        @JoinColumn(table="wforgunit", name = "idorg", referencedColumnName = "idorg", updatable = false, insertable = false),
        @JoinColumn(table="wforgunit", name = "idunit", referencedColumnName = "iduparent", updatable = false, insertable = false)})
    private List<Wforgunit> lstChildren;
    public List<Wforgunit> getChildren() { return lstChildren; }
The error I get is:
Quote:
org.hibernate.AnnotationException: referencedColumnNames(codit, idorg, iduparent) of TabelleOrganigramma.Wforgunit.lstChildren referencing TabelleOrganigramma.Wforgunit not mapped to a single property
I've tried canging the relation to ManytoMany but this time the error is:
Quote:
 com.microsoft.sqlserver.jdbc.SQLServerException: object 'wforgunit_wforgunit' is not valid.
(I've translated error message from italian...)
How can I set my relation?? Where I'm wrong???
Thanks!