躺在沙滩上的小猪

快乐的每一天

#

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