I've got classes with mappings like this:
@Entity
public class CurrencyTable {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@Version
@Column(nullable=false)
private Timestamp version;
@Column(length=32, unique=true)
private String refCode;
@OneToMany(mappedBy="currencyTable", fetch=FetchType.LAZY, cascade = {CascadeType.ALL})
@MapKey(name="currency")
private Map<String, CurrencyTableRate> rateMap = new HashMap<String, CurrencyTableRate>();
}
@Entity
public class CurrencyTableRate{
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
@Version
@Column(nullable=false)
private Timestamp version;
@Column(length=3)
private String currency;
@Basic
private BigDecimal rateValue;
@ManyToOne(optional=false,fetch=FetchType.LAZY)
private CurrencyTable currencyTable;
}
There is one row in CurrencyTable and three rows in CurrencyTableRate referring to the CurrencyTable in database.
When I load CurrencyTable using HQL:
from CurrencyTable where refCode = :refCode
I get an entity with three entries in rateMap, but if I try this:
from CurrencyTable table left outer join fetch table.rateMap where refCode = :refCode
there is only one entry in rateMap.
I looked on query generated by Hibernate and ran it manually - it returned three rows, as expected, so it seems to be a problem with mapping them after fetching. Has anyone encuntered such a problem? I use Hibernate version 3.2.6.ga and Oracle 10g