persistence@glassfish.java.net

redundant joins in Toplink Essentials

From: Sergey Grigoriev <sgr_at_ciklum.net>
Date: Wed, 19 Nov 2008 08:15:40 -0800 (PST)

Hello everyone,
I have detected that toplink sends strange queries to the database. For
example, one of JPA queries I do
is

SELECT DISTINCT booking FROM BookingEntity booking WHERE
booking.passengerSegments.openSegmentReservationDeadline IS NOT NULL AND
booking.passengerSegments.openSegmentReservationDeadline < "2008-11-19
17:05:12" AND booking.passengerSegments.objectStatus = "ACT" AND
booking.passengerSegments.reservationStatus = "OP"

Toplink translates this query into the following SQL statement:

ELECT DISTINCT t0.res_booking_id, t0.is_pnr_compatible, t0.is_group_booking,
t0.creation_datetime, t0.currency_code, t0.record_locator, t0.comments,
t0.requested_ticketing_time, t0.object_status_code, t0.is_pending,
t0.emergency_locked, t0.reservation_datetime, t0.handling_fee,
t0.ticketing_time_limit, t0.external_record_locator,
t0.res_contact_person_id, t0.sec_user_id FROM res_passenger_segment t4,
res_passenger_segment t3, res_passenger_segment t2, res_passenger_segment
t1, res_booking t0 WHERE ((((NOT ((t1.open_segment_reservation_deadline IS
NULL)) AND (t2.open_segment_reservation_deadline < ?)) AND
(t3.object_status_code = ?)) AND (t4.reservation_status_code = ?)) AND
((((t1.res_booking_id = t0.res_booking_id) AND (t2.res_booking_id =
t0.res_booking_id)) AND (t3.res_booking_id = t0.res_booking_id)) AND
(t4.res_booking_id = t0.res_booking_id)))
        bind => [2008-11-19 17:05:12.0, ACT, OP]

As you can see, the query has redundant joins on res_passenger_segment


My mappped classes are

@Entity
@EntityListeners(GuardedObjectListener.class)
@Table(name = BookingEntity.TABLENAME)
public class BookingEntity implements Booking {
...........
 @OneToMany(targetEntity = PassengerSegmentEntity.class, mappedBy =
PassengerSegment.FIELD_BOOKING,
            fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST,
CascadeType.MERGE, CascadeType.REFRESH })
    private List<PassengerSegment> passengerSegments = new
ArrayList<PassengerSegment>();

}

@Entity
@Table(name = PassengerSegmentEntity.TABLENAME)
public class PassengerSegmentEntity implements PassengerSegment {
.............
   @ManyToOne(targetEntity = BookingEntity.class, fetch = FetchType.LAZY)
    @JoinColumn(name = COLUMN_RES_BOOKING_ID, nullable = false)
    private Booking booking;
    public static final String COLUMN_RES_BOOKING_ID = "res_booking_id";

}

I use ToplinkEssentials 10.1.3 and MySQL 5.0, jdk 1.5.0_16

Does anybody know why I have redundant joins ?
-- 
View this message in context: http://www.nabble.com/redundant-joins-in-Toplink-Essentials-tp20583266p20583266.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.