Hi
I have a typical one to many mapping:
Code:
@Entity
@org.hibernate.annotations.Entity(dynamicUpdate=true, dynamicInsert=true)
public class ContractAll
{
// ...
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="contractAll")
public List<ContractHistory> getContractHistory()
{
return contractHistory;
}
And I have a piece of code:
Code:
em.getTransaction().begin();
final ContractAll contract = em.getReference(ContractAll.class, 2L);
final Session sess = (Session)em.getDelegate();
final Date date =
(Date)
sess
.createFilter(contract.getContractHistory(), "select min(this.chValidFrom) where this.chStatus=:chStatus") // DB HIT to ContractAll
.setParameter("chStatus", ChStatusEnum.a)
.uniqueResult(); // DB HIT to filtered collection
em.getTransaction().commit();
In my app there are two database hits (see: DB HIT comments in the source code).
Is it possible to avoid the first database hit (loading proxy from database) and have one and only database hit (to load filtered collection)?
As you can see I don't need (my application doesn't need) to load proxy from database (ContractAll entity) :(
Hibernate have everything in the proxy to perform filtered collection database hit and, I suppose, Hibernate could eliminate this (unnecessary for me) database hit.
Any idea how to decrease the number of DB hits in this code?
Take care,
Adam