-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Unwanted Automatic Lazy Loading
PostPosted: Fri Feb 02, 2007 2:31 am 
Beginner
Beginner

Joined: Thu Nov 20, 2003 1:30 pm
Posts: 27
This is all I call...

Session session = sf.openSession();
session.createCriteria(Report.class).add(
Restrictions.like("title", "%")).list()
session.close();
// Thats it!!

The first generated sql statement is what I expect (They are shown below). But then right after that statement is done it will issue the next statement as many times as there are rows returned for the first. Its really odd because I wouldn't expect it to automatically do that, it should issue that statement when I do something like report.getReportDraft() --- I'm at a loss, any help is greatly appreciated.

Thanks




3.2.1

@Entity
public class Report extends Product implements ReportBase {

@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
ReportDraft reportDraft;

@NotNull
@Length(min = 2, max = 255)
private String subTitle;

@NotNull
@Length(min = 2, max = 3000)
private String excerpt;

@NotNull
private Integer pages;

@Length(max = 128)
private String author;

@NotNull
@Length(min = 2, max = 32765)
private String tableOfContents;

@NotNull
private Date publishedDate;

@Length(min = 2, max = 3000)
private String companiesMentioned;

@Lob
@Column(length = 2000000000)
@Basic(fetch = FetchType.LAZY)
private Blob executiveSummaryPdf;

@Lob
@Column(length = 2000000000)
@Basic(fetch = FetchType.LAZY)
private Blob pdf;
}

@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = "number"),
@UniqueConstraint(columnNames = "name") })
public class Product extends PersistentObject {

@NotNull
@Length(max = 24)
@PartitionedNumber
private String number;

@NotNull
@Length(min = 2, max = 255)
private String title;

@NotNull
@Length(min = 2, max = 3000)
private String description;

@NotNull
@Column(columnDefinition = "CHAR (36)")
private String userId;

@NotNull
private Integer rating;

@NotNull
private Integer visitors;

private String manufacturerPartNumber;

@OneToMany(mappedBy = "product")
@Cascade( { CascadeType.ALL, CascadeType.DELETE_ORPHAN })
private Set<ProductPrice> prices = new HashSet<ProductPrice>();

@ManyToMany
@IndexColumn(name = "priority", base = 1)
private List<Category> categories = new ArrayList<Category>();

private Integer subscriptionCycleOfDays;

@Length(max = 128)
private String name;
}


@Entity
public class ReportDraft extends PersistentObject implements ReportBase {

@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
@PrimaryKeyJoinColumn
Report report;

@ManyToOne
ReviewStatus reviewStatus;

@ManyToOne
Category comment;

@NotNull
@Column(columnDefinition = "CHAR (36)")
private String userId;

@NotNull
@Length(min = 2, max = 255)
private String title;

@NotNull
@Length(min = 2, max = 255)
private String subTitle;

@NotNull
@Length(min = 2, max = 3000)
private String description;

@NotNull
@Length(min = 2, max = 3000)
private String excerpt;

@NotNull
private Integer pages;

@Length(max = 128)
private String author;

@NotNull
@Length(min = 2, max = 32765)
private String tableOfContents;

@NotNull
private BigDecimal singleUserPrice;

@NotNull
private BigDecimal unlimitedUsersPrice;

@NotNull
private Date publishedDate;

@NotNull
Integer rating;

@Length(min = 2, max = 3000)
private String companiesMentioned;

@Lob
@Column(length = 2000000000)
@Basic(fetch = FetchType.LAZY)
private Blob executiveSummaryPdf;

@Lob
@Column(length = 2000000000)
@Basic(fetch = FetchType.LAZY)
private Blob pdf;

@ManyToMany
@IndexColumn(name = "priority", base = 1)
List<Category> categories = new ArrayList<Category>();
}

@MappedSuperclass
abstract public class PersistentObject implements Creatable, Updatable,
Serializable {

@Id
@Length(min = 36, max = 36)
@Column(columnDefinition = "CHAR (36)")
String id = UUID.randomUUID().toString();

@NotNull
Date createdDate;

@NotNull
@Version
Date updatedDate;
}

mysql 5.0.24

1.

SELECT
this_.id AS id45_0_,
this_1_.createdDate AS createdD2_45_0_,
this_1_.updatedDate AS updatedD3_45_0_,
this_1_.NUMBER AS number45_0_,
this_1_.title AS title45_0_,
this_1_.description AS descript6_45_0_,
this_1_.userId AS userId45_0_,
this_1_.rating AS rating45_0_,
this_1_.visitors AS visitors45_0_,
this_1_.manufacturerPartNumber AS manufac10_45_0_,
this_1_.subscriptionCycleOfDays AS subscri11_45_0_,
this_1_.NAME AS name45_0_,
this_.subTitle AS subTitle58_0_,
this_.excerpt AS excerpt58_0_,
this_.pages AS pages58_0_,
this_.author AS author58_0_,
this_.tableOfContents AS tableOfC6_58_0_,
this_.publishedDate AS publishe7_58_0_,
this_.companiesMentioned AS companie8_58_0_,
this_.executiveSummaryPdf AS executiv9_58_0_,
this_.pdf AS pdf58_0_
FROM
Report this_
INNER JOIN Product this_1_
ON this_.id=this_1_.id
WHERE
this_1_.title LIKE ?
ORDER BY
this_1_.createdDate ASC LIMIT ?


2. For every row the following is executed...


SELECT
reportdraf0_.id AS id60_5_,
reportdraf0_.createdDate AS createdD2_60_5_,
reportdraf0_.updatedDate AS updatedD3_60_5_,
reportdraf0_.reviewStatus_id AS reviewS20_60_5_,
reportdraf0_.comment_id AS comment19_60_5_,
reportdraf0_.userId AS userId60_5_,
reportdraf0_.title AS title60_5_,
reportdraf0_.subTitle AS subTitle60_5_,
reportdraf0_.description AS descript7_60_5_,
reportdraf0_.excerpt AS excerpt60_5_,
reportdraf0_.pages AS pages60_5_,
reportdraf0_.author AS author60_5_,
reportdraf0_.tableOfContents AS tableOf11_60_5_,
reportdraf0_.singleUserPrice AS singleU12_60_5_,
reportdraf0_.unlimitedUsersPrice AS unlimit13_60_5_,
reportdraf0_.publishedDate AS publish14_60_5_,
reportdraf0_.rating AS rating60_5_,
reportdraf0_.companiesMentioned AS compani16_60_5_,
reportdraf0_.executiveSummaryPdf AS executi17_60_5_,
reportdraf0_.pdf AS pdf60_5_,
reviewstat1_.id AS id63_0_,
reviewstat1_.createdDate AS createdD2_63_0_,
reviewstat1_.updatedDate AS updatedD3_63_0_,
reviewstat1_.NAME AS name63_0_,
reviewstat2_.reviewStatus_id AS reviewSt6_7_,
reviewstat2_.id AS id7_,
reviewstat2_.locale AS formula14_7_,
reviewstat2_.id AS id64_1_,
reviewstat2_.createdDate AS createdD2_64_1_,
reviewstat2_.updatedDate AS updatedD3_64_1_,
reviewstat2_.NAME AS name64_1_,
reviewstat2_.locale AS locale64_1_,
reviewstat2_.reviewStatus_id AS reviewSt6_64_1_,
category3_.id AS id50_2_,
category3_.createdDate AS createdD2_50_2_,
category3_.updatedDate AS updatedD3_50_2_,
category3_.NAME AS name50_2_,
category3_.userId AS userId50_2_,
category3_.parentCategory_id AS parentCa6_50_2_,
category4_.id AS id50_3_,
category4_.createdDate AS createdD2_50_3_,
category4_.updatedDate AS updatedD3_50_3_,
category4_.NAME AS name50_3_,
category4_.userId AS userId50_3_,
category4_.parentCategory_id AS parentCa6_50_3_,
categorytr5_.category_id AS category7_8_,
categorytr5_.id AS id8_,
categorytr5_.locale AS formula13_8_,
categorytr5_.id AS id51_4_,
categorytr5_.createdDate AS createdD2_51_4_,
categorytr5_.updatedDate AS updatedD3_51_4_,
categorytr5_.NAME AS name51_4_,
categorytr5_.description AS descript5_51_4_,
categorytr5_.locale AS locale51_4_,
categorytr5_.category_id AS category7_51_4_
FROM
ReportDraft reportdraf0_
LEFT OUTER JOIN ReviewStatus reviewstat1_
ON reportdraf0_.reviewStatus_id=reviewstat1_.id
LEFT OUTER JOIN ReviewStatusTranslation reviewstat2_
ON reviewstat1_.id=reviewstat2_.reviewStatus_id
LEFT OUTER JOIN Category category3_
ON reportdraf0_.comment_id=category3_.id
LEFT OUTER JOIN Category category4_
ON category3_.parentCategory_id=category4_.id
LEFT OUTER JOIN CategoryTranslation categorytr5_
ON category3_.id=categorytr5_.category_id
WHERE
reportdraf0_.id=?[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 03, 2007 7:47 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
there is a good explanation on one-to-one and lazyness in the wiki comunity area, have a look. This is probably in the FAQ too

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.