openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nikolas Everett" <nik9...@gmail.com>
Subject Tons of unneeded queries
Date Wed, 30 Apr 2008 15:00:01 GMT
I'm having a problem where one of my dependent objects is fetching the
object it is dependent on, even though that dependent object has already
fetched.


I am using OpenJpa 1.0.2 backed into Postgres 8.2.6.  I have two objects:
Account and TimeDependentAccountData.


@Entity
@Table(uniqueConstraints={@UniqueConstraint(columnNames="uuid")})
public class Account {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    @OneToMany(cascade={CascadeType.PERSIST, CascadeType.REFRESH,
CascadeType.MERGE}, fetch=FetchType.EAGER, mappedBy="account")
    @OrderBy("startTime ASC")
    private List<TimeDependentAccountData> timeDependentAccountData;

...getters and setters...
}


Entity
public class TimeDependentAccountData {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private int id;

    @ManyToOne(cascade = {CascadeType.PERSIST}, fetch = FetchType.EAGER,
optional = false)
    private Account account;

...getters and setters...
}

When I do something like em.createQuery("SELECT a FROM Account") OpenJPA
runs the following SQL queries:
2785 SELECT t0.id, t0.uuid FROM Account t0
2797 SELECT t0.id, t1.id, t1.field1, t1.field2, t1.field3, t1.field4 FROM
Account t0 INNER JOIN TimeDependentAccountData t1 ON t0.id = t1.account_id
ORDER BY t0.id ASC, t1.startTime ASC
115796 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 1
115799 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 2
115800 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 3
115802 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 4
115804 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 5
115805 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 6
115807 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 7
115808 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 8
115810 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 9
115811 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 10
115813 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 11
115814 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 12
115816 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 13
115817 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 14
115819 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 15
115821 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 16
115822 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 17
115824 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 18
115825 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 19
115827 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 20
115828 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 21
115830 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 22
115831 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 23
115833 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 24
115835 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 25
115836 SELECT t1.id, t1.uuid FROM TimeDependentAccountData t0 INNER JOIN
Account t1 ON t0.account_id = t1.id WHERE t0.id = ? [params=(int) 26
And another 400 or so of these.

What can I do to prevent this silliness?

Thanks,

--Nik

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message