|
The bug is involving mainly 3 entities:
@Entity
public class PartnerUser implements Serializable {
...
@OneToMany(cascade={CascadeType.ALL},fetch = FetchType.EAGER,targetEntity = BitcoinAddress.class,mappedBy = "username")
private Collection<BitcoinAddress> bitcoinAddress;
@OneToMany(cascade={CascadeType.ALL},fetch = FetchType.EAGER,targetEntity = LinkedGtpCard.class,mappedBy = "username")
private Collection<LinkedGtpCard> linkedGtpCard;
@Column(unique=false,updatable=true,insertable=true,nullable=true,length=255,scale=0,precision=0)
@Id
private String username;
}
@Entity
public class LinkedGtpCard implements Serializable {
...
@EmbeddedId
private GtpCardIdPK id;
@ManyToOne(optional=true,fetch = FetchType.EAGER,targetEntity = PartnerUser.class)
private PartnerUser username;
}
@Entity
public class BitcoinAddress implements Serializable {
...
@EmbeddedId
private BitcoinAddressIdPK id;
@MapsId("username")@ManyToOne(optional=true,targetEntity = PartnerUser.class)
private PartnerUser username;
}
I'm querying one instance of "PartnerUser", and I'm expecting to have both "bitcoinAddress" and "linkedGtpCard" collections in "PartnerUser" filled correct.
From the content of my database, I know that I have 3 elements of "bitcoinAddress", and 1 element of "linkedGtpCard".
When I loop over both collections I find:
-
3 elements of "bitcoinAddress" => correct
-
3 elements of "linkedGtpCard", referencing the same Entity (same Reference) => incorrect, I was expecting only one element
More over, if I add one element of bitcoinAddress to the database, I have:
-
4 elements of "bitcoinAddress" => correct
-
4 elements of "linkedGtpCard", referencing the same Entity (same Reference) => incorrect, I was expecting only one element
From the logs (I'm not expert), it seems that a query is performed first to have the collection of "bitcoinAddress", and the same query result is reused again in order to extract the collection of "linkedGtpCard".
I have attached the logs (with 4 elements of "bitcoinAddress" in the DB).
|