的确是慢,hibernate本身就比较慢,设计要求也比较高!学习了...

解决方案 »

  1.   

    把源码跟HQL语句发一下,光说看不出来什么
      

  2.   

    1.先确定这15-30秒是否都浪费在查询数据库了
    2.检查User表索引
    3.User表是否关联了其它表,最好加上lazy
    4.改成hql或sql比较下速度
      

  3.   

    速度一样 全都很慢 我怀疑我哪里没映射好 大家给看看吧 很郁闷 贴代码了
    这是映射文件
    <?xml version="1.0" encoding="utf-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"><hibernate-mapping>
        <class name="pojo.Customer" table="customer" catalog="mastery">
            <id name="id" type="java.lang.Integer">
                <column name="id" />
                <generator class="native" />
            </id>
            <!-- 客户简称 -->
            <property name="customerShortname" type="java.lang.String">
                <column name="customer_name" length="36"/>
            </property>
            <!--客户代码  -->
            <property name="customerCode" type="java.lang.String">
                <column name="customer_code" length="36"/>
            </property>
        .......省略12个字段
       </class>
    </hibernate-mapping>
    POJO类我就不贴了 应该没问题 简单的get set下面是我的Dao查询实现
    /**以加载类的形式查询集合 */
    @SuppressWarnings("unchecked")
    public List<Object> findList(Class entity) throws RuntimeException{
    // TODO Auto-generated method stub    

    return (List<Object>) this.getHibernateTemplate().findByCriteria(DetachedCriteria.forClass(entity));

    }
    然后我在ACTION每次需要查那个对象我就直接
    dao.findList(ABC.class);
      

  4.   

    请高人给看看,我觉得这个应该没什么问题 可能问题是出在我的配置上面 这个类在另外一个POJO  A类里面有用到
    关联关系。
      <many-to-one name="Customer" class="ifmsMyPriceWeb.pojo.SaleCustomer" lazy="false" insert="false" update="false">  
                <column name="customer_id"/>  
            </many-to-one> 
      

  5.   

    接着补充发现查询A类的时候 假如A类里面没有对应CustomerID的那一条数据.就会报org.hibernate.ObjectNotFoundException: No row with the given identifier exist [ifmsMyPriceWeb.pojo.DocPort#1]我想应该是我配置关联映射的时候配置错了? 
      

  6.   

    many-to-one里加not-found="ignore",默认exception
      

  7.   

    s column: modifier3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: modifica8_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field10_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field11_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field12_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field13_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field14_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field15_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field16_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field17_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field18_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.loader.Loader.doQuery(699) | result set row: 1
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(172) | returning '8' as column: id3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.loader.Loader.getRow(1173) | result row: EntityKey[ifmsMyPriceWeb.pojo.DocShipcompany#8]
    [QC] DEBUG [http-8080-1] org.hibernate.loader.Loader.loadFromResultSet(1355) | Initializing object from ResultSet: [ifmsMyPriceWeb.pojo.DocShipcompany#8]
    [QC] DEBUG [http-8080-1] org.hibernate.persister.entity.AbstractEntityPersister.hydrate(2031) | Hydrating entity: [ifmsMyPriceWeb.pojo.DocShipcompany#8]
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(172) | returning 'test' as column: shipComp2_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(172) | returning 'test1' as column: shipComp3_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(172) | returning 'test2' as column: shipComp4_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: entryPeo5_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: entryTime3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: modifier3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: modifica8_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field10_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field11_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field12_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field13_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field14_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field15_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field16_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field17_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.type.NullableType.nullSafeGet(166) | returning null as column: field18_3_0_
    [QC] DEBUG [http-8080-1] org.hibernate.loader.Loader.doQuery(721) | done processing result set (2 rows)
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.AbstractBatcher.logCloseResults(389) | about to close ResultSet (open ResultSets: 1, globally: 1)
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.AbstractBatcher.logClosePreparedStatement(374) | about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.AbstractBatcher.closePreparedStatement(533) | closing statement
    [QC] DEBUG [http-8080-1] org.hibernate.loader.Loader.initializeEntitiesAndCollections(851) | total objects hydrated: 2
    [QC] DEBUG [http-8080-1] org.hibernate.engine.TwoPhaseLoad.initializeEntity(107) | resolving associations for [ifmsMyPriceWeb.pojo.DocShipcompany#7]
    [QC] DEBUG [http-8080-1] org.hibernate.engine.TwoPhaseLoad.initializeEntity(206) | done materializing entity [ifmsMyPriceWeb.pojo.DocShipcompany#7]
    [QC] DEBUG [http-8080-1] org.hibernate.engine.TwoPhaseLoad.initializeEntity(107) | resolving associations for [ifmsMyPriceWeb.pojo.DocShipcompany#8]
    [QC] DEBUG [http-8080-1] org.hibernate.engine.TwoPhaseLoad.initializeEntity(206) | done materializing entity [ifmsMyPriceWeb.pojo.DocShipcompany#8]
    [QC] DEBUG [http-8080-1] org.hibernate.engine.StatefulPersistenceContext.initializeNonLazyCollections(790) | initializing non-lazy collections
    [QC] DEBUG [http-8080-1] org.hibernate.transaction.JDBCTransaction.commit(103) | commit
    [QC] DEBUG [http-8080-1] org.hibernate.impl.SessionImpl.managedFlush(337) | automatically flushing session
    [QC] DEBUG [http-8080-1] org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(58) | flushing session
    [QC] DEBUG [http-8080-1] org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(111) | processing flush-time cascades
    [QC] DEBUG [http-8080-1] org.hibernate.event.def.AbstractFlushingEventListener.prepareCollectionFlushes(154) | dirty checking collections
    [QC] DEBUG [http-8080-1] org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(171) | Flushing entities and processing referenced collections
    [QC] DEBUG [http-8080-1] org.hibernate.event.def.AbstractFlushingEventListener.flushCollections(210) | Processing unreferenced collections
    [QC] DEBUG [http-8080-1] org.hibernate.event.def.AbstractFlushingEventListener.flushCollections(224) | Scheduling collection removes/(re)creates/updates
    [QC] DEBUG [http-8080-1] org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(85) | Flushed: 0 insertions, 0 updates, 0 deletions to 2 objects
    [QC] DEBUG [http-8080-1] org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(91) | Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    [QC] DEBUG [http-8080-1] org.hibernate.pretty.Printer.toString(83) | listing entities:
    [QC] DEBUG [http-8080-1] org.hibernate.pretty.Printer.toString(90) | ifmsMyPriceWeb.pojo.DocShipcompany{entryTime=null, modificationTime=null, entryPeople=null, id=8, modifier=null, field=null, field5=null, field4=null, field3=null, field2=null, field10=null, field9=null, shipCompanyChineseName=test1, field8=null, field7=null, field6=null, shipCompanyCode=test, shipCompanyEnglishName=test2}
    [QC] DEBUG [http-8080-1] org.hibernate.pretty.Printer.toString(90) | ifmsMyPriceWeb.pojo.DocShipcompany{entryTime=null, modificationTime=null, entryPeople=null, id=7, modifier=null, field=null, field5=null, field4=null, field3=null, field2=null, field10=null, field9=null, shipCompanyChineseName=COLUMBUS L, field8=null, field7=null, field6=null, shipCompanyCode=COLUMBUS LINE, shipCompanyEnglishName=COLUMBUS LINE}
    [QC] DEBUG [http-8080-1] org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(290) | executing flush
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.ConnectionManager.flushBeginning(469) | registering flush begin
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.ConnectionManager.flushEnding(478) | registering flush end
    [QC] DEBUG [http-8080-1] org.hibernate.event.def.AbstractFlushingEventListener.postFlush(321) | post flush
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.JDBCContext.beforeTransactionCompletion(201) | before transaction completion
    [QC] DEBUG [http-8080-1] org.hibernate.impl.SessionImpl.beforeTransactionCompletion(393) | before transaction completion
    [QC] DEBUG [http-8080-1] org.hibernate.transaction.JDBCTransaction.toggleAutoCommit(193) | re-enabling autocommit
    [QC] DEBUG [http-8080-1] org.hibernate.transaction.JDBCTransaction.commit(116) | committed JDBC Connection
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.JDBCContext.afterTransactionCompletion(215) | after transaction completion
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.ConnectionManager.afterTransaction(302) | transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
    [QC] DEBUG [http-8080-1] org.hibernate.impl.SessionImpl.afterTransactionCompletion(422) | after transaction completion
    [QC] DEBUG [http-8080-1] org.hibernate.impl.SessionImpl.close(273) | closing session
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.ConnectionManager.cleanup(380) | performing cleanup
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.ConnectionManager.closeConnection(441) | releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.JDBCContext.afterTransactionCompletion(215) | after transaction completion
    [QC] DEBUG [http-8080-1] org.hibernate.jdbc.ConnectionManager.afterTransaction(302) | transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
    [QC] DEBUG [http-8080-1] org.hibernate.impl.SessionImpl.afterTransactionCompletion(422) | after transaction completion
      

  8.   

    非常感谢,报错的问题解决了,,,但是查询速度问题依然就是那么慢 我把log4j打印的hibernate查询日志贴出来了 希望能得到解答。谢谢了
      

  9.   

    感谢各位的回复 ,让人想不到的问题是,hibernate查询的效率慢的问题居然是log4j的配置 以下是我的Log4j配置 各位可以看一下 到底是哪里没配置好 引起了hibernate查询的时候 效率变慢 我把它关了就没事了。以下是我的Log4j配置 这个问题我是头一次遇到 希望碰到同样问题的朋友看到 能够解决。#1) org.springframework包下面所有的日志输出的级别设为DEBUG   
    #log4j.logger.org.springframework=INFO   
    #log4j.rootLogger=INFO,appender1   
    #2) 控制台输出   
    #log4j.appender.appender1=org.apache.log4j.ConsoleAppender   
    #log4j.appender.appender1.layout=org.apache.log4j.PatternLayout   
    #log4j.appender.appender1.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss:SSS}[%p]: %m%n   
    # 立即输出   
    #log4j.appender.appender1.immediateFlush=true# log4j.rootCategory=INFO, stdout , R  
     
     #log4j.appender.stdout=org.apache.log4j.ConsoleAppender #log4j.appender.stdout.layout=org.apache.log4j.PatternLayout# log4j.appender.stdout.layout.ConversionPattern=[QC] %p [%t] %C.%M(%L) | %m%n# log4j.appender.R=org.apache.log4j.DailyRollingFileAppender #log4j.appender.R.File=D\:log4j.log# log4j.appender.R.layout=org.apache.log4j.PatternLayout# log4j.appender.R.layout.ConversionPattern=%d-[TS] %p %t %c - %m%n# log4j.logger.com.neusoft=DEBUG#log4j.logger.com.opensymphony.oscache=ERROR# log4j.logger.net.sf.navigator=ERROR #log4j.logger.org.apache.commons=ERROR# log4j.logger.org.apache.struts=WARN #log4j.logger.org.displaytag=ERROR #log4j.logger.org.springframework=WARN #log4j.logger.org.apache.velocity=FATAL #log4j.logger.com.canoo.webtest=WARN# log4j.logger.org.hibernate.ps.PreparedStatementCache=WARN #log4j.logger.org.hibernate=DEBUG# log4j.logger.org.logicalcobwebs=WARN