躺在沙灘上的小豬

          快樂的每一天

          #

          Hibernate Query

          昨天在用hibernate無意中在后臺發現一個很奇怪的問題,一條SQL一直在重復執行,跑了好半天也沒完成:(
          仔細的看了一下,原來是在查詢字典表,先執行一次總的查詢出id,然后分別根據id分別select,這個字典表的內容太多了,而且本身自關聯的。
          當然我也知道這個只是第一次加載慢,第一次加載同時會被緩存,可是這個項目剛剛開始,這個字典表的改動是很頻繁的,需要根據客戶的需求而經常變動,等穩定下來再該回去。

          先修改為sql:

          ?select?c.categoryid?as?{category.Id},?c.categoryname?as?{category.Name}
          ???????????
          from?Tb_Article_Category?c
          ???????????
          where?c.categoryparentid?is null

          跑了一下,沒有通過:(

          Hibernate:?select?c.categoryId?as?categoryId0_0_,c.categoryName?as?category2_0_0_?
          ?????????????????????????????????? from?tb_article_category??c?where?c.categoryParentId?is?
          null

          [
          2006 - 03 - 20 ? 09 : 12 : 38 , 812 ] - ERROR?(JDBCExceptionReporter.java: 72 ) | Column? ' category3_0_0_ ' ?not?found.

          試著將表中所有的字段都寫出來便沒有錯誤了,不太明白為什么非要我寫出所有字段,可是那并是我想要的,我也怕麻煩。

          目前我的做法是直接返回object [],沒有對每條記錄轉化為ArticleCategory對象。
          select ?c.categoryId,c.categoryName? from ?tb_article_category??c? where ?c.categoryParentId? is ? null ?

          ???????? for ?(Object?obj?:?list)? {
          ????????????Object?[]?str?
          =
          ?(Object[])?obj;
          ????????????System.out.println(String.valueOf(str[
          1
          ]));
          ????????}

          沒有修改之前:

          ?

          修改之后:
          ?

          posted @ 2006-03-20 09:15 martin xus| 編輯 收藏

          SVN Service

          http://dark.clansoft.dk/~mbn/svnservice/

          SVN Service Wrapper for Windows

          This is my Win32 Service wrapper for SVN. Source is included, and its in the public domain. No need to copyright this stuff.

          Usage instructions:
          
            SVNService -?                               to display this list
            SVNService -install <svnserve parameters>   to install the service
            SVNService -setup <svnserve parameters>     to change command line parameters for svnserve
            SVNService -remove                          to remove the service
            SVNService -debug                           to run as a console app for debugging
          
          Example:
          
            SVNService -install -d -r c:\svnrepo
            SVNService -setup -d -r c:\otherplace\svnrepo
          
          IMPORTANT:
          
            Make sure you place SVNService.exe in the same directory as svnserve.exe
          

          Special thanks go to Craig Link at Microsoft for creating the initial service.c.

          -Magnus Norddahl

          posted @ 2006-03-17 10:43 martin xus| 編輯 收藏

          IDEA Plugin:GroovyJ

          在最新的EAP版本下跑不起來,害的我又改用了IDEA5.1
          Home Page:
                  http://groovy.codehaus.org/IntelliJ+IDEA+Plugin

          posted @ 2006-03-16 12:54 martin xus| 編輯 收藏

          dwr集成spring

          dwr.xml

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
                  "http://www.getahead.ltd.uk/dwr/dwr10.dtd"
          >
          <dwr>
              
          <allow>
                  
          <create creator="spring" javascript="UserDAO">
                      
          <param name="beanName" value="userDao"/>
                      
          <include method="addUser"/>
                      
          <include method="removeUser"/>
                      
          <include method="findUserByName"/>
                  
          </create>

                  
          <convert converter="bean" match="martin.dwr.demo.model.User">
                      
          <param name="include" value="id,name,password,age"/>
                  
          </convert>

              
          </allow>
          </dwr>

          web.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                  "http://java.sun.com/dtd/web-app_2_3.dtd"
          >
          <web-app>

              
          <context-param>
                  
          <param-name>contextConfigLocation</param-name>
                  
          <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
              
          </context-param>

              
          <listener>
                  
          <listener-class>
                      org.springframework.web.context.ContextLoaderListener
                  
          </listener-class>
              
          </listener>

              
          <servlet>
                  
          <servlet-name>dwr-invoker</servlet-name>
                  
          <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
                  
          <init-param>
                      
          <param-name>debug</param-name>
                      
          <param-value>true</param-value>
                  
          </init-param>
                  
          <init-param>
                      
          <param-name>config-admin</param-name>
                      
          <param-value>WEB-INF/classes/dwr.xml</param-value>
                  
          </init-param>
              
          </servlet>

              
          <servlet-mapping>
                  
          <servlet-name>dwr-invoker</servlet-name>
                  
          <url-pattern>/dwr/*</url-pattern>
              
          </servlet-mapping>
          </web-app>

          applicationContext.xml
              <bean id="userDao" class="martin.dwr.demo.dao.hibernate.HibernateUserDAO">
                  
          <property name="sessionFactory" ref="sessionFactory"/>
              
          </bean>

          瀏覽:http://localhost:8080/demo/dwr/index.html 查看調試信息

          posted @ 2006-03-15 22:44 martin xus| 編輯 收藏

          配置spring,通過Annotations生成SessionFactory

          AnnotationSessionFactoryBean 繼承LocalSessionFactoryBean

          今天用到,查了一下refrence,順便把它貼出來:

          <?xml version="1.0" encoding="UTF-8"?>
          <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
                  "http://www.springframework.org/dtd/spring-beans.dtd"
          >
          <beans>
              
          <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
                  
          <property name="location">
                      
          <value>classpath:jdbc.properties</value>
                  
          </property>
              
          </bean>

              
          <bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
                    destroy-method
          ="close">
                  
          <property name="driverClass">
                      
          <value>${db.driverClass}</value>
                  
          </property>
                  
          <property name="jdbcUrl">
                      
          <value>${db.url}</value>
                  
          </property>
                  
          <property name="properties">
                      
          <props>
                          
          <prop key="c3p0.acquire_increment">5</prop>
                          
          <prop key="c3p0.idle_test_period">100</prop>
                          
          <prop key="c3p0.max_size">100</prop>
                          
          <prop key="c3p0.max_statements">0</prop>
                          
          <prop key="c3p0.min_size">10</prop>
                          
          <prop key="user">${db.user}</prop>
                          
          <prop key="password">${db.pass}</prop>
                      
          </props>
                  
          </property>
              
          </bean>

              
          <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
                  
          <property name="hibernateProperties">
                      
          <props>
                          
          <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                          
          <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                      
          </props>
                  
          </property>
                  
          <property name="dataSource" ref="c3p0DataSource"/>
                  
          <property name="annotatedClasses" value="martin.dwr.demo.model.User"/>
              
          </bean>

              
          <bean id="userDao" class="martin.dwr.demo.dao.hibernate.HibernateUserDAO">
                  
          <property name="sessionFactory" ref="sessionFactory"/>
              
          </bean>
          </beans>

          posted @ 2006-03-15 22:09 martin xus| 編輯 收藏

          僅列出標題
          共28頁: First 上一頁 2 3 4 5 6 7 8 9 10 下一頁 Last 
          主站蜘蛛池模板: 泰来县| 山西省| 安化县| 屯昌县| 犍为县| 镇原县| 阿克苏市| 南开区| 泸定县| 蒙山县| 长岭县| 桃园市| 微山县| 罗源县| 娱乐| 武宁县| 永平县| 普陀区| 兰州市| 南皮县| 德江县| 陈巴尔虎旗| 潜山县| 惠来县| 清河县| 四平市| 宣恩县| 安顺市| 台南县| 曲沃县| 定襄县| 盘锦市| 邯郸县| 文化| 青铜峡市| 鹿邑县| 五河县| 锡林郭勒盟| 新巴尔虎右旗| 太仆寺旗| 余庆县|