Lazy fetch is ignored with "Linked List" like Entity
----------------------------------------------------
Key: EJB-357
URL:
http://opensource.atlassian.com/projects/hibernate/browse/EJB-357
Project: Hibernate Entity Manager
Issue Type: Bug
Components: EntityManager
Affects Versions: 3.3.2.GA
Environment: database: Oracle
Reporter: ALan Cheung
I have an "Linked List" like entity, CustomerVersion, which is defined as
follow....
@Entity
@Table (name="CUST_VER")
@SequenceGenerator (name="seqCustVersionId",
sequenceName="SEQ_CUST_VER_ID")
public class CustomerVersion {
@Id
@GeneratedValue (generator="seqCustVersionId",
strategy=GenerationType.SEQUENCE)
@Column (name="CUST_VER_ID")
private Long versionId;
@Column (name="CUST_AGE")
private Integer age;
@ManyToOne (fetch=FetchType.EAGER)
@JoinColumn (name="CUST_ID", updatable=false, insertable = false)
private Customer master;
@OneToOne (mappedBy = "nextVersion", fetch=FetchType.LAZY, optional=true)
private CustomerVersion previousVersion;
@OneToOne (fetch=FetchType.LAZY, optional=true)
@JoinColumn (name="NEXT_CUST_VER_ID")
private CustomerVersion nextVersion;
@Temporal(TemporalType.DATE)
@Column(name="VER_EFF_DATE")
protected Date versionEffectiveDate;
@Temporal(TemporalType.DATE)
@Column(name="VER_EXPR_DATE")
protected Date versionExpiryDate;
...
...
}
After executing the following, hibernate fetches all the versions once, and issues SQLs to
oracle for fetching all the CustomerVersion one by one. This caused a huge performance
issue, as we have more than 500 versions.
Criteria criteria = session.createCriteria(CustomerVersion.class);
criteria.createAlias("master", "m")
.add( Restrictions.eq( "m.id", masterPk ) )
.addOrder( Order.asc( "versionEffectiveDate" ) );
criteria.list();
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira