मैं हाइबरनेट 4.1.6 का उपयोग कर रहा हूं और एक सूची बनाई गई गति के साथ समस्याएं हैं। मैं निम्नलिखित क्वेरी चला रहा हूं।हाइबरनेट क्वेरी.सूची() धीमी क्यों है?
public void doQuery(final Baz baz){
final Query query = getSessionFactory().getCurrentSession().createQuery(
"select c.id, foo.someValue from Foo as foo "+
"join foo.a as a"+
"join foo.b as b "+
"join b.c as c "+
"where baz=:baz"
);
query.setParameter("baz", baz);
Long start=System.currentTimeMillis();
final List<Object[]> list = query.list();
Long end=System.currentTimeMillis();
System.out.println((end-start));
}
मैंने डेटाबेस पर भेजी गई वास्तविक क्वेरी प्राप्त करने के लिए हाइबरनेट डीबगिंग सेट की है। मैंने उस क्वेरी को सीधे डेटाबेस में चलाया और यह 0.015 एमएस में 23,000 पंक्तियां लौटा दी। तो, मैं अनुमान लगा रहा हूं कि सवाल मुद्दा नहीं है। उपरोक्त उदाहरण से पता चलता है कि उस सूची को बनाने में ~ 32 सेकंड लगते हैं। क्या ऐसा कुछ है जो इसे गति देने के लिए किया जा सकता है?
अद्यतन: मैं विधि createSQLQuery() हाइबरनेट डिबगिंग क्वेरी का उपयोग कर उपयोग करने की कोशिश है और यह बस के रूप में विधि createQuery() के रूप में धीमी गति से भाग गया।
अद्यतन: मैं एक राज्यविहीन सत्र का उपयोग करने की कोशिश की, लेकिन यह बस के रूप में धीमी गति से भाग गया।
अद्यतन: मैं कुछ आंकड़े (सही पर hibernate.generate_statistics ध्वज की स्थापना) outputted लेकिन कुछ भी मेरे लिए चौंकाने वाली लग रहा है:
Hibernate SessionFactory Statistics [
Number of connection requests[4]
Number of flushes done on the session (either by client code or by hibernate[3]
The number of completed transactions (failed and successful).[3]
The number of transactions completed without failure[3]
The number of sessions your code has opened.[4]
The number of sessions your code has closed.[3]
Total number of queries executed.[4]
Time of the slowest query executed.[28258]
the number of collections fetched from the DB.[6]
The number of collections loaded from the DB.[6]
The number of collections that were rebuilt[0]
The number of collections that were 'deleted' batch.[0]
The number of collections that were updated batch.[0]
The number of your objects deleted.[0]
The number of your objects fetched.[1]
The number of your objects actually loaded (fully populated).[204]
The number of your objects inserted.[1]
The number of your object updated.[0]
]
Hibernate SessionFactory Query Statistics [
total hits on cache by this query[0]
total misses on cache by this query[0]
total number of objects put into cache by this query execution[0]
Number of times this query has been invoked[1]
average time for invoking this query.[28258]
maximum time incurred by query execution[28258]
minimum time incurred by query execution[28258]
Number of rows returned over all invocations of this query[23303]
]
अद्यतन: मैं एक ही सुस्ती देखने के लिए जब एक ScrollableResults से अगले() कर एक मूल प्रश्न से। ध्यान दें कि मैं लूप में कुछ भी नहीं कर रहा हूं।
ScrollableResults results = query.scroll();
Long start=System.currentTimeMillis();
while (results.next()) {
//do nothing
}
Long end=System.currentTimeMillis();
System.out.println((end-start));
एक uncommited हो सकता है लेनदेन कार्यों को पकड़ना। –
आप अपने हाइबरनेट एसक्यूएल को प्रिंट करना चाहते हैं। सबसे अधिक संभावना एक एन + 1 चयन मुद्दा है। –
जॉर्डन, मुझे इस प्रश्न को धारण करने वाले किसी भी लेनदेन की जानकारी नहीं है। जॉन, मैंने उपरोक्त वर्णित एसक्यूएल मुद्रित किया और क्वेरी ठीक है। – user973479