[hibernate-issues] [Hibernate-JIRA] Commented: (EJB-357) Lazy fetch is ignored with "Linked List" like Entity

S.Schnabl (JIRA) noreply at atlassian.com
Mon May 5 10:01:35 EDT 2008


    [ http://opensource.atlassian.com/projects/hibernate/browse/EJB-357?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_30119 ] 

S.Schnabl commented on EJB-357:
-------------------------------

If you look closer at the @OneToOne Annotation, you will notice, that the default fetch type for OneToOne relations is EAGER. The FAQ states the following on lazy 1:1: http://www.hibernate.org/117.html#A18

> 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.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list