Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Newbie mapping question

Paolo,
 
When you add a card to the collection you must ensure that the backpointer (idcustomer) from that card is also set.
 
Cheers,
Guy
----- Original Message -----
Sent: Thursday, September 11, 2008 10:04 AM
Subject: Re: [eclipselink-users] Newbie mapping question

Thanks Guy,
But i didn't solved my problem! i'm posting all my code :


CUSTOMER ENTITY (table with 2 colums named (id, message))
____________________________________________________
@Entity
@Table(name = "customer")
public class Customer implements Serializable {
   
    private static final long serialVersionUID = 1L;
   
    @Id
    @Column(name = "id", nullable = false)
    private Integer id;
    @Column(name = "message")
    private String message;
    @OneToMany(mappedBy = "idcustomer")
    private Collection<Card> cardCollection;


    public Serializable getMessage() {
        return message;
    }

    public void setMessaggio(String _message) {
        this.message = _message;
    }
   
    public Collection<Card> getCardCollection() {
        return cardCollection;
    }

    public void setCardCollection(Collection<Card> _cardCollection) {
        this.cardCollection = _cardCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Customer)) {
            return false;
        }
        Customer other = (Customer) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "newpackage.Customer[id=" + id + "]";
    }

}

CARD ENTITY (table with 3 colums named (id, biometricpwd, idcustomer))
_____________________________________________________________
@Entity
@Table(name = "card")
public class Card implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @Column(name = "id", nullable = false)
    private Integer id;
    @Column(name = "biometricpwd")
    private Boolean biometricpwd;
    @JoinColumn(name = "idcustomer", referencedColumnName = "id")
    @ManyToOne
    private Customer idcustomer;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Boolean getBiometricpwd() {
        return biometricpwd;
    }

    public void setBiometricpwd(Boolean biometricpwd) {
        this.biometricpwd = biometricpwd;
    }

    public Customer getIdcustomer() {
        return idcustomer;
    }

    public void setIdcustomer(Customer _idcustomer) {
        this.idcustomer = _idcustomer;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Card)) {
            return false;
        }
        Card other = (Card) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "newpackage.Card[id=" + id + "]";
    }
}

Idcustomer is an imported key from table customer.
How can i obtain all cards finding a customer??
Thanks in advance.

2008/9/11 Guy Pelletier <guy.pelletier@xxxxxxxxxx>
Hi,

Your mapped by is incorrect and should be specified as follows: mappedBy="relateda"

And your JoinColumn is inversed. It should be

@JoinColumn(name="Akeyname", referencedColumnName="Bkeyname")

Cheers,
Guy

----- Original Message ----- From: "SerFingolfin" <paolo.trisio@xxxxxxxxx>
To: <eclipselink-users@xxxxxxxxxxx>
Sent: Thursday, September 11, 2008 6:26 AM
Subject: [eclipselink-users] Newbie mapping question




Hi to everybody.
My project works on two entities with a "one to many" relation.
A entity defines a collection of B elements as described here :

@OneToMany(cascade = CascadeType.ALL, mappedBy = Bkeyname, fetch =
FetchType.EAGER)
private Collection bcollection;

And B relates to A like this:

@JoinColumn(name = Bkeyname, referencedColumnName = Akeyname)
@ManyToOne
private A relateda;

Fetch = FetchType.EAGER should grant me that every "find" operation
on A should retrieve every B entity related to A, am i wrong?
This is not happening in my project! I always see null values on B
collection,
what am i doing wrong?
Thanks in advance
--
View this message in context: http://www.nabble.com/Newbie-mapping-question-tp19430896p19430896.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top