Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » JPA selecting, what should be lazy loaded, when not necessary
JPA selecting, what should be lazy loaded, when not necessary [message #1083180] Fri, 09 August 2013 15:39 Go to next message
George g is currently offline George gFriend
Messages: 1
Registered: August 2013
Junior Member
i have a table mapped to this class:

@Entity(name = "status_history")
    @Table
    public class StatusChange implements Comparable<StatusChange> {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    @Column(name = "when_")
    @Temporal(TemporalType.TIMESTAMP)
    private Date when;
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinColumn(name = "ordering_id")
    private Ordering ordering;
    private Short status;
    ...

@Override
public int hashCode() {
    return id.intValue();
}

@Override
public boolean equals(Object o) {
    if (o instanceof StatusChange) {
        StatusChange sc = (StatusChange) o;
        if (id == null) {
            return false;
        }
        return id.equals(sc.getId());
    }
    return false;
}
    ...


which has 5006 rows. Why logging shows, that when i execute this query:

Query query = em.createQuery("SELECT DISTINCT sh FROM status_history sh");
 return query.getResultList();

JPA is fetching also the related entity Ordering (and its related entities):

[EL Fine]: sql: 2013-08-09 17:02:52.631--ServerSession(27039955)--Connection(12972016)--Thread(Thread[main,5,main])--SELECT ID, TYPE, anniversary_newspapers, anniversary_newspapers_type, AUTHOR, copy_color, copy_format, decorated_folder, decorated_folder_note, delivery_type, publishing_description, SIGNATURE, TITLE, USAGE, work_amount, work_amount_desc, work_type, year_, BARCODE, comment_, denial_reason, EXHIBITION, exhibition_name, further_processing, LZA, no_new_scans, ONLINE, RESTORATION, SMALL, URGENT FROM ordered_object WHERE (ID = ?)
    bind => [54]
[EL Fine]: sql: 2013-08-09 17:02:52.632--ServerSession(27039955)--Connection(12972016)--Thread(Thread[main,5,main])--SELECT ID, TYPE, cancel_comment, claim_comment, COMMUNICATION, EDITOR, internal_id, LOCATION, STATUS, YEAR, yearly_number, billing_contact_id, oo_id, orderer_id, accumulated, customer_created, estimated_price, no_barcode, no_object, accumulated_id FROM ORDERING WHERE (oo_id = ?)
    bind => [54]
[EL Fine]: sql: 2013-08-09 17:02:52.634--ServerSession(27039955)--Connection(12972016)--Thread(Thread[main,5,main])--SELECT ID, _comment, control_finished, CONTROLLER, date_of_entry, empty_pages, scan_finished, scan_method1, scan_method2, scan_operator, SCANNER, SENDER, thumbnail_number, total_pages, oo_id FROM SCAN_INFO WHERE (oo_id = ?)
    bind => [54]
[EL Fine]: sql: 2013-08-09 17:02:52.635--ServerSession(27039955)--Connection(12972016)--Thread(Thread[main,5,main])--SELECT ID, onb_employee, contact_id FROM ORDERER WHERE (ID = ?)
    bind => [54]


and the query takes 30sec. What am i missing here? thanks a lot in advance!
Re: JPA selecting, what should be lazy loaded, when not necessary [message #1085869 is a reply to message #1083180] Tue, 13 August 2013 13:32 Go to previous message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

LAZY is only supported when weaving is enabled. To allow weaving your must either being using JavaEE, use the EclipseLink agent to start your JVM, ot use static weaving.

http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving


James : Wiki : Book : Blog : Twitter
Previous Topic:@AdditionalCriteria breaks on @LOB updates
Next Topic:Delete Query Redirects in Second time
Goto Forum:
  


Current Time: Fri Mar 29 07:55:52 GMT 2024

Powered by FUDForum. Page generated in 0.02778 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top