论坛首页 Java企业应用论坛

我的开发规范分享(二)- 禁用Hibernate HQL,QBC,QBE编程(1)

浏览 29930 次
精华帖 (0) :: 良好帖 (3) :: 新手帖 (19) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-09-26  
   用过一次hibernate,感觉可以这样用,简单操作的就用hibernate提供的支持,复杂的性能要求高的就写sql得了。
    这样用起来比ibatis配置文件稍微少了些,不用所有sql语句都写在文件里面
    折中处理吧,性能应该不是什么问题
    所以说hibernate太高深不敢用,我觉得大可不必,用它简单实用的就可以了,高深的不好控制的东西就不用了,老实自己写sql得了
    
   
0 请登录后投票
   发表时间:2008-09-26  
upheart 写道
很想知道,如果一个查询条件是动态的,比如根据用户输入的查询条件来构造,那这种方案怎么做?

还是要编写 查询语句 增加判断~~
0 请登录后投票
   发表时间:2008-09-26  
yanghuw 写道

简单查询HQL,复杂查询sql-query

upheart 写道
很想知道,如果一个查询条件是动态的,比如根据用户输入的查询条件来构造,那这种方案怎么做?

    动态条件可以通过Where子句来判断条件,比如你需要查询订单,订单号的条件是可选的,你可以在查询语句中这么写:ORDERNO is null OR o.ORDERNO=:ORDERNO,这种方式和if-else一样,如果条件为空就判断下一个条件,不为空就比较条件,就是效率会稍微差一点

 

 

 

沒必要這麼做, iBATIS里有判斷null值的標籤.

 

在iBATIS手册第48页

 

<isEqual> Checks the equality of a property and a value, or another property.
<isNotEqual> Checks the inequality of a property and a value, or another property.
<isGreaterThan> Checks if a property is greater than a value or another property.
<isGreaterEqual> Checks if a property is greater than or equal to a value or another property.
<isLessThan> Checks if a property is less than a value or another property.
<isLessEqual> Checks if a property is less than or equal to a value or another property.

 

<isPropertyAvailable> Checks if a property is available (i.e is a property of the parameter bean)
<isNotPropertyAvailable> Checks if a property is unavailable (i.e not a property of the parameter bean)
<isNull> Checks if a property is null.
<isNotNull> Checks if a property is not null.
<isEmpty> Checks to see if the value of a Collection, String or String.valueOf() property is null or empty (“” or size() < 1).
<isNotEmpty> Checks to see if the value of a Collection, String or String.valueOf() property is not null and not empty (“” or size() < 1).

 

0 请登录后投票
   发表时间:2008-09-26  
cyberblue 写道

yanghuw 写道

简单查询HQL,复杂查询sql-query

upheart 写道
很想知道,如果一个查询条件是动态的,比如根据用户输入的查询条件来构造,那这种方案怎么做?

    动态条件可以通过Where子句来判断条件,比如你需要查询订单,订单号的条件是可选的,你可以在查询语句中这么写:ORDERNO is null OR o.ORDERNO=:ORDERNO,这种方式和if-else一样,如果条件为空就判断下一个条件,不为空就比较条件,就是效率会稍微差一点





沒必要這麼做, iBATIS里有判斷null值的標籤.


在iBATIS手册第48页


Checks the equality of a property and a value, or another property.
Checks the inequality of a property and a value, or another property.
Checks if a property is greater than a value or another property.
Checks if a property is greater than or equal to a value or another property.
Checks if a property is less than a value or another property.
Checks if a property is less than or equal to a value or another property.


Checks if a property is available (i.e is a property of the parameter bean)
Checks if a property is unavailable (i.e not a property of the parameter bean)
Checks if a property is null.
Checks if a property is not null.
Checks to see if the value of a Collection, String or String.valueOf() property is null or empty (&ldquo;&rdquo; or size() < 1).
Checks to see if the value of a Collection, String or String.valueOf() property is not null and not empty (&ldquo;&rdquo; or size() < 1).




是啊,问题是感觉就是在用iBATIS的标签写这类判断逻辑?这样做合适么?逻辑一复杂,可维护性就不好了,又得不到IDE强大重构的帮助。
0 请登录后投票
   发表时间:2008-12-04  
我也很不明白。

现在很多企业需要别人会用hibernate。又不跨数据库操作,又要把它弄到项目中去。那么多的包弄到项目中,感觉很N。
0 请登录后投票
   发表时间:2008-12-04  


本人赞同楼主的做法,命名查询的性能很好。hql既然无法替代sql,就可以不用,系统修改最大的部分就是sql部分,集中放置sql是个不错的选择。

0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics