-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: 70 nachträgliche selects?
PostPosted: Sat Oct 07, 2006 11:34 am 
Beginner
Beginner

Joined: Fri Sep 01, 2006 3:35 pm
Posts: 21
Hibernate version:
3.1

das hier wird ausgeführt:
Code:
"from ArtikelBean a " +
      "left join fetch a.gesamtwertung " +
      "left join fetch a.varianten " +
      "left join fetch a.empfehlungen " +
      "left join fetch a.einzelwertungen e " +
      "left join fetch e.kunde " +
      "";


ein artikel hat verschiedene einzelbewertungen, und diese haben jeweils einen kunden.

das generierte sql-statement ist ok, es liefert alle nötigen informationen. trotzdem wird noch ca. 70 mal "select * from kunde where uid = ?" nachgeschoben. ich habe keine erklärung dafür.
nur die einzelwertungen referenzieren kunden, und die fetche ich ja mit.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 1:05 pm 
Senior
Senior

Joined: Fri May 14, 2004 9:37 am
Posts: 122
Location: Cologne, Germany
Ähnliches habe ich heute auch erlebt und leider bisher noch keine Lösung gefunden, ausser einem Criteria, was ich nicht mehr so mag, da das generierte SQL der Criteria leider nicht so performant ist, wie die SQL oder HQL Queries.
Bei Dir würde das dann so oder ähnlich aussehen.
session.createCriteria(ArtikelBean.class).createAlias("einzelwertung", "e").setFetchMode("gesamtwertung", FetchMode.JOIN).setFetchMode("varianten", FetchMode.JOIN).setFetchMode("empfehlungen", FetchMode.JOIN)
.setFetchMode("e.kunde", FetchMode.JOIN)

Falls ich das noch mit dem HQL oder dem SQL hinbekomme, dann werde ich das ebenfalls posten. IMHO denke ich es liegt irgendwo im Mapping File oder ist ein Bug, wobei ich vom Mapping ausgehe.

_________________
regards

Olaf

vote if it helped


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 7:56 am 
Newbie

Joined: Tue Feb 07, 2006 8:10 pm
Posts: 1
Location: Norway
Hmm, hat das Kunde objekt eine "one-to-many" referanze nach ArtikelBean?
Das war nämlich das Problem bei mir, die referanze war "inverse" und für jedige Kunde ich von die DB fangt wollte Hibernate alle Artikeln für die Kunde gefangen -> Viele Queries!

(Nein, ich habe Deutsch zeit 6 Jahre nich geschrieben ;) )


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 11:23 am 
Senior
Senior

Joined: Fri May 14, 2004 9:37 am
Posts: 122
Location: Cologne, Germany
@aNThrahee I thought this was also the problem on my side so I removed the the one-to-many relation from the mapping but this didn't changed the behaviour. Still getting this nice n + 1 selects :)

Für Deutschsprachige Leser: Ich habe auch zuerst an die one-to-many Relation innerhalb des Mappings gedacht und diese entfernt, leider ohne einen sichtbaren Erfolg.

_________________
regards

Olaf

vote if it helped


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 2:58 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Poste mal bitte mapping und den Quellkode, der die Abfrage macht. Werden die Selects sofort gemacht oder erst später, wenn Du auf Daten zugreifst?

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 9:24 am 
Senior
Senior

Joined: Fri May 14, 2004 9:37 am
Posts: 122
Location: Cologne, Germany
RefPersonRolesProject.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="de.xcom.ticketsystem.pojo.RefPersonRolesProject" table="ref_person_roles_project" schema="public">
<cache usage="read-write"/>
<id name="refPersonRolesProjectId" type="integer">
<column name="ref_person_roles_project_id" />
<generator class="native">
<param name="sequence">ref_person_roles_project_ref_person_roles_project_id_seq</param>
</generator>
</id>
<many-to-one name="roles" class="de.xcom.ticketsystem.pojo.Roles">
<column name="roles_id" />
</many-to-one>
<many-to-one name="project" class="de.xcom.ticketsystem.pojo.Project">
<column name="project_id" />
</many-to-one>
<many-to-one name="person" class="de.xcom.ticketsystem.pojo.Person">
<column name="person_id" />
</many-to-one>
<property name="rightGranted" type="boolean">
<column name="right_granted" />
</property>
</class>
</hibernate-mapping>


Project.hbm.xml:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="de.xcom.ticketsystem.pojo.Project" table="project" schema="public">
<cache usage="read-write"/>
<id name="projectId" type="integer">
<column name="project_id" />
<generator class="native">
<param name="sequence">project_project_id_seq</param>
</generator>
</id>
<many-to-one name="workflow" class="de.xcom.ticketsystem.pojo.Workflow" fetch="join">
<column name="workflow_id" />
</many-to-one>
<property name="name" type="string">
<column name="name" length="50" not-null="true" />
</property>
<property name="description" type="string">
<column name="description" />
</property>
<property name="shortcut" type="string">
<column name="shortcut" length="20" not-null="true" />
</property>
<property name="recordState" type="string">
<column name="record_state" length="1" not-null="true" />
</property>
<property name="personIdCreate" type="integer">
<column name="person_id_create" not-null="true" />
</property>
<property name="datetimeCreate" type="timestamp">
<column name="datetime_create" length="8" not-null="true" />
</property>
<property name="personIdUpdate" type="integer">
<column name="person_id_update" />
</property>
<property name="datetimeUpdate" type="timestamp">
<column name="datetime_update" length="8" />
</property>
<property name="actualVersion" type="float">
<column name="actual_version" precision="4" scale="0" />
</property>
<property name="releaseVersion" type="float">
<column name="release_version" precision="4" scale="0" />
</property>
<property name="exposeTicketsToCustomer" type="boolean">
<column name="expose_tickets_customer" not-null="true" default="false"/>
</property>
<set name="escalations" inverse="true">
<key>
<column name="project_id" />
</key>
<one-to-many class="de.xcom.ticketsystem.pojo.Escalation" />
</set>
<set name="refProjects" inverse="true" fetch="join">
<key>
<column name="project_id" />
</key>
<one-to-many class="de.xcom.ticketsystem.pojo.RefProject" />
</set>
<set name="refRightsProject" inverse="true">
<key>
<column name="project_id" />
</key>
<one-to-many class="de.xcom.ticketsystem.pojo.RefRightsProject" />
</set>
</class>
</hibernate-mapping>

Code im DAO:

public List<RefPersonRolesProject> getAllPersonRolesProjectOfActivePersons() throws HibernateException {
Session session = getSession();

String activePersonRoles = "select distinct RPRP.* from REF_PERSON_ROLES_PROJECT RPRP join PERSON P on RPRP.PERSON_ID = P.PERSON_ID join PROJECT PR on RPRP.PROJECT_ID = PR.PROJECT_ID where P.RECORD_STATE = 'A'";
List<RefPersonRolesProject> result = session.createSQLQuery( activePersonRoles ).addEntity("RPRP", RefPersonRolesProject.class).list();
return result;
}

EJB Code:

public List<RefPersonRolesProject> getAllProjectPersonRoles( ) throws TicketsystemServerException {
log.info("Get RefPersonRolesProject started");
try {
Long start = System.nanoTime();
List<RefPersonRolesProject> result = DAOFactory.DEFAULT.getRefPersonRolesProjectDAO().getAllPersonRolesProjectOfActivePersons( );
Long end = System.nanoTime();
String message = "Method PersonBcBean.getAllProjectPersonRoles() took " + ((end - start) / 1000000) + " ms Number of Records " + result.size();
log.info( message );
return result;
} catch (HibernateException e) {
log.error(e);
throw new TicketsystemServerException( e.getMessage() );
}
}

Nachdem ich getAllPersonRolesProjectOfActivePersons( ) aufrufe sehe ich dann die Selects laufen.

FetchDepth = 1

Noch ein Zusatz. Methode kann zwischen 30 Sekunden und 190 Sekunden nur für die Abfrage brauchen.

_________________
regards

Olaf

vote if it helped


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 23, 2006 9:55 am 
Expert
Expert

Joined: Tue Nov 23, 2004 7:00 pm
Posts: 570
Location: mostly Frankfurt Germany
Vermutlich werden die ganzen many-to-one Objekte geholt.

Versuch mal folgende Query:

Code:
select rprp from RefPersonRolesProject rprp left join fetch rprp.person p left join fetch rprp.project where p.RECORD_STATE = 'A'

_________________
Best Regards
Sebastian
---
Training for Hibernate and Java Persistence
Tutorials for Hibernate, Spring, EJB, JSF...
eBook: Hibernate 3 - DeveloperGuide
Paper book: Hibernate 3 - Das Praxisbuch
http://www.laliluna.de


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 24, 2006 3:50 am 
Newbie

Joined: Tue Aug 29, 2006 10:56 am
Posts: 15
Ich habe gerade auch Probleme mit many-to-one Assoziationen. Lazy Loading funktioniert nicht korrekt.

Siehe:

many-to-one lazy seems to be broken in 3.1.x
http://opensource.atlassian.com/projects/hibernate/browse/HHH-1435

Der Bug soll ab 3.1.3 behoben sein.

Leider funktioniert das bei mir unter 3.1.3 auch nicht.
Hier mein Mapping:

Code:
<hibernate-mapping>
   <class name="de.mba.MyClass"
      table="MyTable">
      <id name="poi" type="string">
         <column name="POI" length="22" />
         <generator class="assigned" />
      </id>
      <property name="lupdDatetime" type="timestamp">
         <column name="LUPD_DATETIME" length="26" />
      </property>
      <property name="lupdProcess" type="string">
         <column name="LUPD_PROCESS" length="30" />
      ...
      
      <many-to-one name="assoc1"
         class="de.mba.MyAssoc"
         insert="false" update="false" not-found="ignore">
         <column name="POI" />
      </many-to-one>
      
   </class>
</hibernate-mapping>

Defaultmäßig sollte ja lazy Loading verwendet werden. Auch das explizite
Definieren des attributes lazy='proxy' funktioniert nicht.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.