The only fix for that I found was using the component instead of entity. But the performance of using components is worse for some reason. So that's not the way to go.
Hibernate version:
3.3.1
Mapping documents:
@Entity
@org.hibernate.annotations.Entity(mutable = false)
@Table(name = "demo_tmp_fin_header")
public class TmpFinHeader {
@Id
@Column(name = "edw_doc_id")
private String edwDocId;
@Column(name = "period")
private Date period;
@OneToMany
@JoinColumn(name = "edw_doc_id")
@org.hibernate.annotations.BatchSize(size = 100)
private Set<TmpFinData> tmpFinDataSet = new HashSet<TmpFinData>();
// getters, setters
}
@Entity
@org.hibernate.annotations.Entity(mutable = false)
@Table(name = "demo_tmp_fin_data")
public class TmpFinData {
@EmbeddedId
private TmpFinDataId tmpFinDataId;
@Column(name = "amount")
private BigDecimal amount;
// getters, setters
}
@Embeddable
public class TmpFinDataId implements Serializable {
@Column(name = "edw_doc_id")
private String edwDocId;
@Column(name = "amount_id")
private String amountId;
// getters, setters, equals, hashCode
}
Code between sessionFactory.openSession() and session.close():
TmpFinHeader header = hibernateTemplate.get(TmpFinHeader.class, 1);
header.getTmpFinDataSet().size();
Name and version of the database you are using:
Oracle 9i
The generated SQL (show_sql=true):
select
tmpfindata0_.edw_doc_id as edw2_1_,
tmpfindata0_.amount_id as amount1_1_,
tmpfindata0_.amount_id as amount1_1_0_,
tmpfindata0_.edw_doc_id as edw2_1_0_,
tmpfindata0_.amount as amount1_0_
from
gl_loan.demo_tmp_fin_data tmpfindata0_
where
tmpfindata0_.edw_doc_id=?
|