Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Unexpected Queries

Hello Michael,

OneToOne and ManyToOne mappings require weaving inorder to be lazy. Weaving allows the JPA provider use placeholders for relationships and then intercept calls to the relationship to instantiate them. This is not required for collection relationships (1:m and M:M) because they use an interface which allows JPA providers to use placeholders by default: This is why lazy is only a hint on 1:1 and M:1 relationshps, while the default on 1:M and M:M.

for more information on weaving in EclipseLink.

Best Regards,

Michael Simons wrote:

Assume the following part of our model
Scenario (N:1) LoginUser (N:1) Language
No attribute is marked "FetchType.EAGER" but all are "LAZY".

My test program does the following JPQ:
  Query q = em.createQuery ("select s from Scenario s where = 1");
  Scenario scenario = (Scenario)q.getSingleResult ();

But EL generates the following queries:
  SELECT scenario_id, creation_date, vrsion, nme, ext_id, alt_ex_id, jdo_version, login_user_id
  FROM scenario WHERE (scenario_id = 1);

  SELECT login_user_id, passwd, mail, phone, alias, nme, login, lnguage_id, sales_office_id
  FROM login_user WHERE (login_user_id = 1);

  SELECT lnguage_id, nme, abbreviation FROM lnguage WHERE (lnguage_id = 1);

So for a reason I don't know of, EL descides to load the "owner" (login_user) of the scenario as
well as the "language" (lnguage_id) of that user.

EL behaves the same on other JPQL-Queries, that leads to a problem, because every line is
selected in a single statement. So this leads to a mass of SQL statements.

My persistence.xml:
  <persistence-unit name="otee" transaction-type="RESOURCE_LOCAL">

      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.url"
      <property name="javax.persistence.jdbc.user" value="otcs"/>
      <property name="javax.persistence.jdbc.password" value="otcs"/>
      <property name="eclipselink.persistence-context.flush-mode" value="Commit" />
      <!-- To print SQL statements  -->
      <property name="eclipselink.logging.level" value="FINE" />


Any hint is appreciated.

Kind Regards, Michael
eclipselink-users mailing list

Back to the top