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.

See
http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Using_EclipseLink_JPA_Weaving
for more information on weaving in EclipseLink.

Best Regards,
Chris

Michael Simons wrote:
Hello,

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 s.id = 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">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <exclude-unlisted-classes>true</exclude-unlisted-classes>
		
		<class>net.uniopt.domain.config.Scenario</class>
		<class>net.uniopt.domain.sys.Language</class>
		<class>net.uniopt.domain.usrmngmt.LoginUser</class>

    <properties>
      <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
      <property name="javax.persistence.jdbc.url"
value="jdbc:mysql://smithers:3306/ot_diermeier_324"/>
      <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" />
    </properties>

  </persistence-unit>


Any hint is appreciated.

Kind Regards, Michael
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top