-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: self relation
PostPosted: Wed Mar 09, 2011 5:00 am 
Newbie

Joined: Tue Jun 15, 2010 5:41 am
Posts: 1
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.